iPhone设备、型号、版本
2013-01-15 21:42
281 查看
NSString *modelname = [[UIDevice currentDevice]model]; if ([modelname isEqualToString:@"iPhone"]) { // iPhone } if ([modelname isEqualToString:@"IPod Touch"]) { // iPod touch } if ([modelname isEqualToString:@"iPhone Simulator"]) { // iPhone Simulator }
#import <TargetConditionals.h> #if TARGET_OS_IPHONE // iPhone Device #endif #if TARGET_IPHONE_SIMULATOR // iPhone Simulator #endif #if !TARGET_IPHONE_SIMULATOR // iPhone Device #endif
可以通过 uname 函数取得当前机器的版本。
struct utsname u; uname(&u); NSString *machine = [NSString stringWithCString:u.machine]; if ([machine isEqualToString:@"iPhone1,1"]) { // iPhone 1G } if ([machine isEqualToString:@"iPhone1,2"]) { // iPhone 3G } if ([machine isEqualToString:@"iPhone2,1"]) { // iPhone 3GS } if ([machine isEqualToString:@"iPod1,1"]) { // iPod touch 1G } if ([machine isEqualToString:@"iPod2,1"]) { // iPod touch 2G } if ([machine isEqualToString:@"iPod3,1"]) { // iPod touch Late2009 }
或者通过 sysctlbyname() 函数取得:
- (NSString *) platform { size_t size; sysctlbyname("hw.machine", NULL, &size, NULL, 0); char *machine = malloc(size); sysctlbyname("hw.machine", machine, &size, NULL, 0); /* Possible values: "iPhone1,1" = iPhone 1G "iPhone1,2" = iPhone 3G "iPhone2,1" = iPhone 3GS "iPod1,1" = iPod touch 1G "iPod2,1" = iPod touch 2G */ NSString *platform = [NSString stringWithCString:machine]; free(machine); return platform; }
使用 UIDevice 的属性 systemVersion 来得到
NSString *osversion = [UIDevice currentDevice].systemVersion; if ([osversion isEqualToString:@"2.1"]) { // iPhone } if ([osversion isEqualToString:@"2.2.1"]) { // iPod touch } if ([osversion isEqualToString:@"3.0"]) { // iPhone Simulator }
iPhone SDK 版本宏
// 当前系统支持的最小版本 __IPHONE_OS_VERSION_MIN_REQUIRED // 当前系统支持的最大版本 __IPHONE_OS_VERSION_MAX_ALLOWED
比如用 iPhone OS SDK 3.1.2 编译的程序
__IPHONE_OS_VERSION_MIN_REQUIRED == __IPHONE_3_0 __IPHONE_OS_VERSION_MAX_ALLOWED == __IPHONE_3_1
可以在程序中使用下面类似的 $ifdef 语句
#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_2_2 // iPhone OS SDK 3.0 以后版本的处理 #else // iPhone OS SDK 3.0 之前版本的处理 #endif
iPhone OS SDK 4 推出的时候,可以
#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_2_2 #if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_3_1 // iPhone OS SDK 4.0 以后版本的处理 #else // iPhone OS SDK 3.0 ~ 4.0 版本的处理 #endif #else // iPhone OS SDK 3.0 之前版本的处理 #endif
相关文章推荐
- iphone手机型号对应iOS系统版本及设备标签
- 获取设备型号、SDK版本及其系统版本
- iOS获取设备型号 系统版本(最新iPhone5s)
- Android获取设备型号、SDK版本及其系统版本
- Swift - 获取应用名称、应用版本、设备型号、系统版本等信息
- 各代iphone ipad iPod各种信息 获取设备型号等等整理
- 获取 设备 版本 型号 是否联网
- 获得设备型号(含iPhone6 , iPhone 6+)
- Android获取设备型号、SDK版本及其系统版本
- 获取设备型号,app版本,提交时间,网络类型等信息
- 【Android】获取设备型号、SDK版本及其系统版本
- iOS Device Types(设备型号:iPhone Model)
- 关于获取ios系统版本号 与 获取iphone设备型号的相关代码搜集
- iOS SDK详解之UIDevice(系统版本,设备型号...)
- iPhone设备型号列表
- 安卓获取设备的系统类型,系统版本,手机生产厂商和手机型号
- AndroidUtils(一)手机信息大全(设备ID、厂商、型号、系统、IMEI、SDK版本等)
- Swift - 获取应用名称、应用版本、设备型号、系统版本等信息
- ios获取手机型号、系统版本、设备唯一标识符、手机运营商等
- 如何获得WM设备信息,如型号、操作系统版本等