如何判断您的代码是在iPhone还是iPhone3G上运行?

Aft*_*hew 22 iphone ios

我试图确定我的代码是在iPhone还是iPhone3G上运行.我的第一次尝试是在UIKit中使用UIDevice类,但iPhone和iPhone3G都返回相同的响应:

NSLog([[UIDevice currentDevice] name]); // Name of the phone as named by user
NSLog([[UIDevice currentDevice] uniqueIdentifier]); // A GUID like string
NSLog([[UIDevice currentDevice] systemName]); // "iPhone OS" 
NSLog([[UIDevice currentDevice] systemVersion]); // "2.2.1"
NSLog([[UIDevice currentDevice] model]); // "iPhone" on both devices
NSLog([[UIDevice currentDevice] localizedModel]); // "iPhone" on both devices
Run Code Online (Sandbox Code Playgroud)

这些是UIDevice允许您查询的唯一参数.

我在Foundation Framework中看了一下,但还没有找到合适的电话.

我敢肯定有一些我可以查询的硬件(例如位置服务中的东西),但这似乎是一个黑客.有谁知道确定这个的简单方法?

eph*_*ent 21

iPhone运行OS X. 以下是如何在Macintosh桌面上确定硬件平台. 是iPhone上的方式.这是完全一样的.

简而言之,sysctlbyname("hw.machine", str, sz, 0, 0)将平台名称写入str.对于iPhone和iPhone 3G,这恰好分别是"iPhone1,1"或"iPhone1,2".


Ste*_*owe 6

我不是iPhone开发人员,但检查底层平台而不是平台功能几乎总是错误的选择.如果iPhone获得了您所需的功能,您仍然无法运行.你也有可能在下一代iPhone 4.0(或其他任何名称)上做出错误的决定.