iOS 어플상에서 기기의 종류를 알아올 수 있는 코드이다.

#include <sys/sysctl.h>    // sysctlbyname 의 사용을 위해

// 모델 정보 보기 - 상세히
+ (NSString *) platform {
    size_t size;
    sysctlbyname("hw.machine", NULL, &size, NULL, 0);
    char *machine = malloc(size);
    sysctlbyname("hw.machine", machine, &size, NULL, 0);
    /*
     Possible values:
     "i386" = iPhone Simulator
     "iPhone1,1" = iPhone 1G
     "iPhone1,2" = iPhone 3G
     "iPhone2,1" = iPhone 3GS
     "iPhone3,1" = iPhone 4
     "iPod1,1"   = iPod touch 1G
     "iPod2,1"   = iPod touch 2G
     "iPod3,1"   = iPod touch 3G
     */
    NSString *platform = [NSString stringWithUTF8String:machine];
    free(machine);
    
    return platform;
}

출처 : http://cafe.naver.com/mcbugi/81305


+ Recent posts