简体   繁体   English

区分iPhone 4和iPhone 4S

[英]Distinguish between iPhone 4 and iPhone 4S

I need to distinguish iPhone 4S from iPhone 4. I went through the posts and got the following code. 我需要区分iPhone 4S和iPhone 4.我浏览了帖子并获得了以下代码。 Please let me know if this is the only way of doing it and confirm that there is no problem by Apple if used. 如果这是唯一的方法,请告诉我,如果使用Apple确认没有问题。

            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. 对于4S,iPhoneVersion字符串会给我iPhone4,1和iPhone 4会说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 ). 在CDMA型号的情况下,iPhone 4也可称为iPhone3,3这里是一个不太新的列表 )。 In general it is much safer and "forward compatible" to test for the capabilities of the platform (eg [someSystemClass respondsToSelector:@selector(someMethodName)] or similar) rather than manually determining the capabilities based on the device model. 通常,它更安全且“向前兼容”以测试平台的功能(例如[someSystemClass respondsToSelector:@selector(someMethodName)]或类似),而不是基于设备模型手动确定功能。 Could you say why you need to distinguish between iPhone 4 and 4S? 你能说出为什么需要区分iPhone 4和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. 正如其他人所建议的那样,您应该专注于您需要的功能,而不是选择特定的设备(如果Apple推出变体或下一个型号时将会中断)。 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. iPad上推出的唯一iPhone应用程序是那些进行硬件模型检测的应用程序,因为他们不知道iPad即将推出,因此无法查找特定的设备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 . 如果您的应用程序绝对无法在iPhone 4上运行,由于蓝牙4.0低功耗支持等特定硬件要求,您最好将bluetooth-le添加到Info.plist中的UIRequiredDeviceCapabilities ,就像我在这里描述的那样。 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. 这将阻止用户甚至在非4S设备上安装您的应用程序,但是留下了可能用于未来iPhone的可能性,这些iPhone很可能具有蓝牙低功耗硬件。

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 . 如果您需要扩展硬件功能以利用A5,您可能需要通过使用glGetString( GL_EXTENSIONS )并检查APPLE_shadow_samplers扩展来检查对A5所具有的一些新OpenGL ES扩展的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. A4上没有这些扩展,但是A5上有这些扩展,应该可以用于Apple硬件的下一次迭代。

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. 您也可以使用轻微记录的新Core Bluetooth框架在运行时测试设备中是否存在4.0低功耗硬件,但我没有花太多时间使用该框架。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM