I need to distinguish iPhone 4S from iPhone 4. I went through the posts and got the following code. Please let me know if this is the only way of doing it and confirm that there is no problem by Apple if used.
struct utsname systemInfo;
uname(&systemInfo);
NSString *iPhoneVersion = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
For 4S, iPhoneVersion string will give me iPhone4,1 and iPhone 4 will say iPhone3,1.
Thanks for your suggestions.
iPhone 4 may also be called iPhone3,3
in the case of the CDMA model (here is a not-quite-up-to-date list). In general it is much safer and "forward compatible" to test for the capabilities of the platform (e.g. [someSystemClass respondsToSelector:@selector(someMethodName)]
or similar) rather than manually determining the capabilities based on the device model. Could you say why you need to distinguish between iPhone 4 and 4S?
As others have suggested, rather than selecting for a specific device (which will break if and when Apple rolls out variations or the next model), you should focus on what capabilities you need. Just about the only iPhone applications that broke when the iPad launched were ones that did hardware model detection, because they had no idea that the iPad was coming and thus couldn't look for that specific device ID.
If your application absolutely cannot run on an iPhone 4, due to specific hardware requirements like Bluetooth 4.0 Low Power support, you'd be best served to add the bluetooth-le
to your UIRequiredDeviceCapabilities
in your Info.plist, like I describe here. That will prevent users from even installing your application on a non-4S device, but leaves open the possibility of this working for future iPhones which will most likely have Bluetooth Low Power hardware.
If you need to scale hardware capabilities to take advantage of the A5, you might want to look into checking for support for some of the new OpenGL ES extensions that the A5 has, by using glGetString( GL_EXTENSIONS )
and checking for extensions like APPLE_shadow_samplers
. These extensions aren't present on the A4, but are there on the A5 and should be there for the next couple of iterations of Apple's hardware.
You might also be able to use the lightly documented new Core Bluetooth framework to test for the presence of 4.0 Low Power hardware in your device at runtime, but I haven't spent much time with that framework.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With