14

如何通过 iOS 检测我当前的设备名称?

4

4 回答 4

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];
}
于 2009-10-09T14:15:51.603 回答
19

这是 Erica Sadun 编写的一个类,它为此提供了广泛的功能:

http://github.com/erica/uidevice-extension/blob/master/UIDevice-Hardware.m

查看 repo 的其余部分 - 还有一些类将被证明对细粒度的设备查询非常有用。

于 2010-03-23T19:51:41.147 回答
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.
于 2009-10-09T21:12:23.430 回答
0

您正在寻找的是:

UIDevice *device = [UIDevice currentDevice];
NSString *model = [device model];

这将返回设备是 iPhone 还是 iPod touch

于 2013-03-13T16:45:23.460 回答