确定iphone的版本 [英] Identify iphone's version
问题描述
我正在开发一个只能安装在iPhone 4及更高版本中的应用程序。我还要通过 UIRequiredDeviceCapabilities和设备兼容性矩阵。我需要更多解决方案。
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.
推荐答案
首先,您可以使用 UIDevice $接收模型作为字符串c $ c> class:
Well, first of all you can receive the model as a string using the UIDevice
class:
[[UIDevice currentDevice] model]
这将返回类似iPod touch或iPhone的内容。
This will return something like "iPod touch" or "iPhone".
你可以得到确切的结果模型平台使用以下代码:
(您必须 #include< sys / types.h>
和< sys / sysctl.h>
)
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);
现在 platform
是包含代的字符串该设备,例如:
Now platform
is a string containing the generation of the device, e.g.:
-
iPhone1,1
iPhone 2G (第一部iPhone) -
iPhone1,2
iPhone 3G -
iPhone2,1
iPhone 3GS - <$ c iPhone 4
-
iPhone5,1
或iPhone5,2
iPhone 5
iPhone3,2
li> iPhone4,1
iPhone 4S iPhone1,1
for the iPhone 2G (the first iPhone)iPhone1,2
for the iPhone 3GiPhone2,1
for the iPhone 3GSiPhone3,1
oriPhone3,2
for the iPhone 4iPhone4,1
for the iPhone 4SiPhone5,1
oriPhone5,2
for the iPhone 5
请注意,iPhone 4平台逗号前面的数字实际上是 3 ,而不是4.
使用此字符串可以隔离此数字并检查是否它大于或等于3:
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
}
}
但是:你可以实际检查屏幕的比例,因为iPhone 4是第一款带有视网膜显示器的iPhone:
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
这篇关于确定iphone的版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!