失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > iPhone/iPad/iPod touch编程时版本区分

iPhone/iPad/iPod touch编程时版本区分

时间:2020-08-27 03:48:29

相关推荐

iPhone/iPad/iPod touch编程时版本区分

写程序时,可能需要对应各种不同的iPhone iOS的不同,型号的不同,区分代码如下: 可以从 UIDevice 的属性 model 得到在现在执行的环境。例子如下: NSString *modelname = [[UIDevice currentDevice]model]; if ([modelname isEqualToString:@"iPhone"]) { // iPhone } if ([modelname isEqualToString:@"IPod Touch"]) { // iPod touch } if ([modelname isEqualToString:@"iPhone Simulator"]) { // iPhone Simulator } 也可以通过宏定义区分 #if TARGET_OS_IPHONE // iPhone Device #endif #if TARGET_IPHONE_SIMULATOR // iPhone Simulator #endif #if !TARGET_IPHONE_SIMULATOR // iPhone Device #endif ios设备版本的区分-iphone3gs,iphone4.... ios提供了几种c函数来获得相应信息如下 struct utsname u; uname(&u); ///-----get device struct info 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 Late } 或者 - (NSString *) platform { size_t size; sysctlbyname("hw.machine", NULL, &size, NULL, 0); char *machine = malloc(size); sysctlbyname("hw.machine", machine, &size, NULL, 0);///-----get device struct info /* 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; }

如果觉得《iPhone/iPad/iPod touch编程时版本区分》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。