当前设备型号(iPhone3Gs or iPhone4)验证

[1] 、加入头文件   

 #include <sys/sysctl.h>

[2]、添加类,实现

- (NSString *) platform
{  
    size_t size;  
    sysctlbyname("hw.machine", NULL, &size, NULL, 0);  
    char *machine = malloc(size);  
    sysctlbyname("hw.machine", machine, &size, NULL, 0);  
    NSString*platform = [NSStringstringWithCString:machine encoding:NSUTF8StringEncoding];  
    free(machine);  
    return platform;  
}

[3]、定义字符串接收,结果可能的值为:

逗号后面数字解释:(i386是指模拟器)
1-WiFi版
2-GSM/WCDMA 3G版
3-CDMA版


AppleTV(2G)    (AppleTV2,1)
iPad           (iPad1,1)
iPad2,1        (iPad2,1)Wifi版
iPad2,2        (iPad2,2)GSM3G版
iPad2,3        (iPad2,3)CDMA3G版
iPhone         (iPhone1,1)
iPhone3G       (iPhone1,2)
iPhone3GS      (iPhone2,1)
iPhone4        (iPhone3,1)
iPhone4(vz)    (iPhone3,3)iPhone4 CDMA版
iPhone4S       (iPhone4,1)
iPodTouch(1G)  (iPod1,1)
iPodTouch(2G)  (iPod2,1)
iPodTouch(3G)  (iPod3,1)
iPodTouch(4G)  (iPod4,1)

posted @ 2012-09-17 12:44  周宏伟  阅读(496)  评论(0编辑  收藏  举报