如何通过iOS检测我当前的设备名称?
答案 0 :(得分:22)
无论您使用的是iPhone还是iPod Touch:
UIDevice *device = [UIDevice currentDevice];
NSString *systemName = [device systemName];
要检测操作系统的版本:
UIDevice *device = [UIDevice currentDevice];
NSString *systemVersion = [device systemVersion];
要检测特定型号,您需要测试只有该型号具有的功能,以便检测iPhone 3GS,检查相机上的视频功能:
#define SOURCETYPE UIImagePickerControllerSourceTypeCamera
// does the device have a camera?
if ([UIImagePickerController isSourceTypeAvailable:SOURCETYPE]) {
// if so, does that camera support video?
NSArray *mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:SOURCETYPE];
bool isA3GS = [mediaTypes containsObject:kUTTypeMovie];
}
答案 1 :(得分:19)
这是Erica Sadun撰写的一个课程,为此提供了广泛的功能:
http://github.com/erica/uidevice-extension/blob/master/UIDevice-Hardware.m
查看其余的repo - 还有一些类可以证明对细粒度设备查询非常有用。
答案 2 :(得分:9)
来自UIDevice.h文件:
[[UIDevice currentDevice] name] // e.g. "My iPhone"
[[UIDevice currentDevice] model] // e.g. @"iPhone", @"iPod Touch"
[[UIDevice currentDevice] localizedModel] // localized version of model
[[UIDevice currentDevice] systemName] // e.g. @"iPhone OS"
[[UIDevice currentDevice] systemVersion] // e.g. @"2.0"
[[UIDevice currentDevice] uniqueIdentifier] // a string unique to each device based on various hardware info.
答案 3 :(得分:0)
您正在寻找的是:
UIDevice *device = [UIDevice currentDevice];
NSString *model = [device model];
这将返回设备是iPhone还是iPod touch