我试图确定我的代码是在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中看了一下,但还没有找到合适的电话.
我敢肯定有一些我可以查询的硬件(例如位置服务中的东西),但这似乎是一个黑客.有谁知道确定这个的简单方法?
在我的通用应用程序中,我需要检查当前设备是iPad还是iPhone.我该如何以编程方式执行此操作?我打算把代码放在我的viewDidLoad中.