IOS开发之--获取设备类型和系统版本号

IOS开发之--获取设备类型和系统版本号,第1张

概述#import "sys/utsname.h" /* * the model @"i386" on the simulator@"iPod1,1" on iPod Touch@"iPod2,1" on iPod Touch Second Generation@"iPod3,1" on iPod Touch Third Generation@"iP
#import "sys/utsname.h" 
/* *    the model @"i386"      on the simulator@"iPod1,1"   on iPod touch@"iPod2,1"   on iPod touch Second Generation@"iPod3,1"   on iPod touch Third Generation@"iPod4,1"   on iPod touch Fourth Generation@"iPhone1,1" on iPhone@"iPhone1,2" on iPhone 3G@"iPhone2,1" on iPhone 3GS@"iPad1,1"   on iPad@"iPad2,1"   on iPad 2@"iPad3,1"   on iPad 3 (aka new iPad)@"iPhone3,1" on iPhone 4@"iPhone4,1" on iPhone 4S@"iPhone5,1" on iPhone 5@"iPhone5,2" on iPhone 5iPhone 4 is iPhone3,1 and iPhone3,2iPhone 4S is iPhone4,1 iPad 2 is iPad2,1 iPad2,2 and iPad2,3 depending on version (GSM etc)iPad 3 is iPad3,1 iPad3,2 and iPad3,3 depending on version (GSM etc)*    @return null */ 
- (voID)getDeviceModelAndSysversion {         //here use sys/utsname.h         struct utsname systemInfo;         uname(&systemInfo);         //get the device model            Nsstring *model = [Nsstring stringWithCString:systemInfo.machine enCoding:NSUTF8StringEnCoding]);         Nsstring *version =    [[UIDevice currentDevice] systemVersion]; } 
- (Nsstring *)getModel {    size_t size;    sysctlbyname("hw.machine",NulL,&size,0);    char *model = malloc(size);    sysctlbyname("hw.machine",model,0);    Nsstring *sDeviceModel = [Nsstring stringWithCString:model enCoding:NSUTF8StringEnCoding];    free(model);                                  if ([sDeviceModel isEqual:@"i386"])      return @"Simulator";  //iPhone Simulator    if ([sDeviceModel isEqual:@"iPhone1,1"]) return @"iPhone1G";   //iPhone 1G    if ([sDeviceModel isEqual:@"iPhone1,2"]) return @"iPhone3G";   //iPhone 3G    if ([sDeviceModel isEqual:@"iPhone2,1"]) return @"iPhone3GS";  //iPhone 3GS    if ([sDeviceModel isEqual:@"iPhone3,1"]) return @"iPhone4 AT&T";  //iPhone 4 - AT&T    if ([sDeviceModel isEqual:@"iPhone3,2"]) return @"iPhone4 Other";  //iPhone 4 - Other carrIEr    if ([sDeviceModel isEqual:@"iPhone3,3"]) return @"iPhone4";    //iPhone 4 - Other carrIEr    if ([sDeviceModel isEqual:@"iPhone4,1"]) return @"iPhone4S";   //iPhone 4S    if ([sDeviceModel isEqual:@"iPhone5,1"]) return @"iPhone5";    //iPhone 5 (GSM)    if ([sDeviceModel isEqual:@"iPod1,1"])   return @"iPod1stGen"; //iPod touch 1G    if ([sDeviceModel isEqual:@"iPod2,1"])   return @"iPod2ndGen"; //iPod touch 2G    if ([sDeviceModel isEqual:@"iPod3,1"])   return @"iPod3rdGen"; //iPod touch 3G    if ([sDeviceModel isEqual:@"iPod4,1"])   return @"iPod4thGen"; //iPod touch 4G    if ([sDeviceModel isEqual:@"iPad1,1"])   return @"iPaDWiFi";   //iPad Wifi    if ([sDeviceModel isEqual:@"iPad1,2"])   return @"iPad3G";     //iPad 3G    if ([sDeviceModel isEqual:@"iPad2,1"])   return @"iPad2";      //iPad 2 (WiFi)    if ([sDeviceModel isEqual:@"iPad2,2"])   return @"iPad2";      //iPad 2 (GSM)    if ([sDeviceModel isEqual:@"iPad2,3"])   return @"iPad2";      //iPad 2 (CDMA)    Nsstring *aux = [[sDeviceModel componentsSeparatedByString:@","] objectAtIndex:0];//If a newer version exist    if ([aux rangeOfString:@"iPhone"].location!=NSNotFound) {        int version = [[aux stringByReplacingOccurrencesOfString:@"iPhone" withString:@""] intValue];        if (version == 3) return @"iPhone4"        else if (version >= 4 && version < 5) return @"iPhone4s";	else if (version >= 5) return @"iPhone5"    }    if ([aux rangeOfString:@"iPod"].location!=NSNotFound) {        int version = [[aux stringByReplacingOccurrencesOfString:@"iPod" withString:@""] intValue];        if (version >=4 && version < 5) return @"iPod4thGen";         else if (version >=5) return @"iPod5thGen";    }    if ([aux rangeOfString:@"iPad"].location!=NSNotFound) {        int version = [[aux stringByReplacingOccurrencesOfString:@"iPad" withString:@""] intValue];        if (version ==1) return @"iPad3G";        if (version >=2 && version < 3) return @"iPad2";        else if (version >= 3)return @"new iPad";    }    //If none was found,send the original string    return sDeviceModel;}
总结

以上是内存溢出为你收集整理的IOS开发之--获取设备类型和系统版本号全部内容,希望文章能够帮你解决IOS开发之--获取设备类型和系统版本号所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/1092868.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-28
下一篇2022-05-28

发表评论

登录后才能评论

评论列表(0条)

    保存