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

Rah*_*yas 14 iphone objective-c device-name ios

我想检测我当前的设备名称.如何通过iPhone SDK检测到它?另外我如何检测iPhone是否没有插入SIM卡?

mmc*_*mmc 22

无论您使用的是iPhone还是iPod Touch:

UIDevice *device = [UIDevice currentDevice];
NSString *systemName = [device systemName];
Run Code Online (Sandbox Code Playgroud)

要检测操作系统的版本:

UIDevice *device = [UIDevice currentDevice];
NSString *systemVersion = [device systemVersion];
Run Code Online (Sandbox Code Playgroud)

要检测特定模型,您需要测试只有该模型具有的某些功能,以便检测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];
}
Run Code Online (Sandbox Code Playgroud)

  • 以下任一项都将解决它.1)将MobileCoreServices框架添加到项目中2)将#import <MobileCoreServices/UTCoreTypes.h>添加到将引用选择器的头文件中.或者,您可以将导入添加到预编译的头文件(.pch)中,以便整个项目中的UTCoreTypes常量可用. (5认同)
  • 根据我的经验,你需要做1和2. (2认同)

jtr*_*rim 19

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

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

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


Ado*_*lfo 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.
Run Code Online (Sandbox Code Playgroud)