How do I detect whether I have iPhone 2G,3G,3GS

懵懂的女人 提交于 2019-11-26 13:08:02

问题


How to detect my current device name through iOS?


回答1:


Whether you are on an iPhone or a iPod Touch:

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

To detect the version of the OS:

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

To detect a specific model, you would need to test for some capability that only that model has, so to detect an iPhone 3GS, check for a video capability on the camera:

#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];
}



回答2:


Here is a class written by Erica Sadun that provides extensive capabilities for this:

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

Check out the rest of the repo - there are a few more classes that would prove to be really useful for fine-grained device querying.




回答3:


From the UIDevice.h file:

[[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.



回答4:


What you are looking for is this:

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

This will return whether the device is an iPhone or iPod touch



来源:https://stackoverflow.com/questions/1543925/how-do-i-detect-whether-i-have-iphone-2g-3g-3gs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!