-1

I'm developing an app which can only be installed in iPhone 4 and later versions.I also go through UIRequiredDeviceCapabilities and Device Compatibility Matrix.I need more solution.

Ramz
  • 596
  • 1
  • 6
  • 23
Sonu
  • 937
  • 1
  • 10
  • 39
  • 1
    Are you saying you only want your app to work on iPhone devices, not iPods or iPads? – Richard J. Ross III Apr 01 '13 at 11:52
  • 2
    @NimitParekh that seems a bit unnecessary as you can set a target OS version in your build settings. I think he's talking about removing support for a specific device. – Richard J. Ross III Apr 01 '13 at 11:53
  • This is probably a Bad Idea. Apple has their compatibility matrix to decide which devices an app is compatible with; if they find out that you're checking the device at run time and then (I assume) quitting the app, they'll probably pull it from the store. That's a bad user experience. – bdesham Apr 01 '13 at 14:15
  • For iPhone 5S & 5C platform string, see this post http://stackoverflow.com/questions/18854244/what-is-platform-string-for-iphone-5s-5c/18900927#18900927 – Trung Sep 20 '13 at 16:39

1 Answers1

2

Well, first of all you can receive the model as a string using the UIDevice class:

[[UIDevice currentDevice] model]

This will return something like "iPod touch" or "iPhone".

You can get the exact model platform using the following code:
(you have to #include <sys/types.h> and <sys/sysctl.h>)

size_t size;
sysctlbyname("hw.machine", NULL, &size, NULL, 0);
char *machine = malloc(size);
sysctlbyname("hw.machine", machine, &size, NULL, 0);
NSString *platform = @(machine); // Old syntax: [NSString stringWithCString:machine encoding:NSUTF8StringEncoding]
free(machine);

Now platform is a string containing the generation of the device, e.g.:

  • iPhone1,1 for the iPhone 2G (the first iPhone)
  • iPhone1,2 for the iPhone 3G
  • iPhone2,1 for the iPhone 3GS
  • iPhone3,1 or iPhone3,2 for the iPhone 4
  • iPhone4,1 for the iPhone 4S
  • iPhone5,1 or iPhone5,2 for the iPhone 5

Note that the number in front of the comma of the iPhone 4 platform is actually 3, not 4. Using this string you can isolate this number and check if it is greater than or equal to 3:

if ([[[UIDevice currentDevice] model] isEqualToString:@"iPhone"]) {
    if ([[[platform componentsSeparatedByString:@","][0] substringFromIndex:6] intValue] >= 3) {
        // Device is iPhone 4 or newer
    } else {
        // Device is older than iPhone 4
    }
}

However: You can actually check the screen's scale, since the iPhone 4 is the first iPhone with a retina display:

[[UIScreen mainScreen] scale]  // Returns 2.0f on the iPhone 4 and newer and 1.0f on older devices