你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS開發綜合 >> iOS學習筆記30—檢測硬件平台版本號

iOS學習筆記30—檢測硬件平台版本號

編輯:IOS開發綜合

 


#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);
}

 

 

 

  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved