如何检测我是否有iPhone 2G,3G,3GS

问题描述 投票:14回答:4

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

ios objective-c iphone device-name
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];
}

19
投票

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

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

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


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.

0
投票

你在寻找的是:

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

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

© www.soinside.com 2019 - 2024. All rights reserved.