当前位置:编程学习 > wap >>

iOS学习笔记30—检测硬件平台版本号

 


#include <sys/types.h>

#include <sys/sysctl.h>

 

 

 

- (void)showPlatform {
   
    int mib[2];
    size_t len;
    char *machine;
   
    mib[0] = CTL_HW;
    mib[1] = HW_MACHINE;
    sysctl(mib, 2, NULL, &len, NULL, 0);
    machine = malloc(len);
    sysctl(mib, 2, machine, &len, NULL, 0);
   
    NSString *platform = [NSString stringWithCString:machine encoding:NSASCIIStringEncoding];
    free(machine);
   
    if ([platform isEqualToString:@"iPhone1,1"])    platform = @"iPhone 1G";
    if ([platform isEqualToString:@"iPhone1,2"])    platform = @"iPhone 3G";
    if ([platform isEqualToString:@"iPhone2,1"])    platform = @"iPhone 3GS";
    if ([platform isEqualToString:@"iPhone3,1"])    platform = @"iPhone 4";
    if ([platform isEqualToString:@"iPod1,1"])      platform = @"iPod Touch 1G";
    if ([platform isEqualToString:@"iPod2,1"])      platform = @"iPod Touch 2G";
    if ([platform isEqualToString:@"iPod3,1"])      platform = @"iPod Touch 3G";
    if ([platform isEqualToString:@"iPod4,1"])      platform = @"iPod Touch 4G";
    if ([platform isEqualToString:@"iPad1,1"])      platform = @"iPad";
    if ([platform isEqualToString:@"iPad2,1"])      platform = @"iPad 2 (WiFi)";
    if ([platform isEqualToString:@"iPad2,2"])      platform = @"iPad 2 (GSM)";
    if ([platform isEqualToString:@"iPad2,3"])      platform = @"iPad 2 (CDMA)";
    if ([platform isEqualToString:@"i386"])         platform = @"Simulator";
   
    NSLog(@"Device:%@",platform);
}

 

 

 

补充:移动开发 , IOS ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,