确定iphone的版本 [英] Identify iphone's version

查看:51
本文介绍了确定iphone的版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个只能安装在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 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

  • iPhone3,1
    iPhone3,2 li> iPhone4,1 iPhone 4S
  • iPhone5,1 iPhone5,2 iPhone 5

  • 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

请注意,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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆