Develop
2014.05.24 21:54
[ios] iOS에서 디바이스 종류 알아오기
Views 3764 Comment 0
다음과 같은 함수를 작성
# 플랫폼 체크
+ (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 = [NSString stringWithUTF8String:machine]; free(machine); return platform; }
위의 함수는 클래스 함수로 정의하였으나 인스턴스 함수로 정의하여도 동작함
# 버전 체크
+ (int) machine { NSString *platform = [self platform]; /* iPhone */ if ([platform isEqualToString:@"iPhone1,1"]) return 1;// @"iPhone 2G"; if ([platform isEqualToString:@"iPhone1,2"]) return 2;// @"iPhone 3G"; if ([platform isEqualToString:@"iPhone2,1"]) return 3;// @"iPhone 3GS"; if ([platform isEqualToString:@"iPhone3,1"]) return 4;// @"iPhone 4"; if ([platform isEqualToString:@"iPhone3,3"]) return 4;// @"Verizon iPhone 4"; if ([platform isEqualToString:@"iPhone4,1"]) return 5;// @"iPhone 4S"; if ([platform isEqualToString:@"iPhone5,1"]) return 6;// @"iPhone 5 (GSM)"; if ([platform isEqualToString:@"iPhone5,2"]) return 6;// @"iPhone 5 (GSM+CDMA)"; if ([platform isEqualToString:@"iPhone5,3"]) return 6;// @"iPhone 5C (GSM)"; if ([platform isEqualToString:@"iPhone5,4"]) return 6;// @"iPhone 5C (Global)"; if ([platform isEqualToString:@"iPhone6,1"]) return 7;// @"iPhone 5S (GSM)"; if ([platform isEqualToString:@"iPhone6,3"]) return 7;// @"iPhone 5S (Global)"; /* iPod Touch */ if ([platform isEqualToString:@"iPod1,1"]) return 11;// @"iPod Touch 1G"; if ([platform isEqualToString:@"iPod2,1"]) return 12;// @"iPod Touch 2G"; if ([platform isEqualToString:@"iPod3,1"]) return 13;// @"iPod Touch 3G"; if ([platform isEqualToString:@"iPod4,1"]) return 14;// @"iPod Touch 4G"; if ([platform isEqualToString:@"iPod5,1"]) return 15;// @"iPod Touch 5G"; /* iPad */ if ([platform isEqualToString:@"iPad1,1"]) return 1;// @"iPad"; if ([platform isEqualToString:@"iPad2,1"]) return 2;// @"iPad 2 (WiFi)"; if ([platform isEqualToString:@"iPad2,2"]) return 2;// @"iPad 2 (GSM)"; if ([platform isEqualToString:@"iPad2,3"]) return 2;// @"iPad 2 (CDMA)"; if ([platform isEqualToString:@"iPad2,4"]) return 2;// @"iPad 2 (Wi‑Fi Rev A)"; if ([platform isEqualToString:@"iPad2,5"]) return 4;// @"iPad mini (WiFi)"; if ([platform isEqualToString:@"iPad2,6"]) return 4;// @"iPad mini (GSM)"; if ([platform isEqualToString:@"iPad2,7"]) return 4;// @"iPad mini (GSM+CDMA)"; if ([platform isEqualToString:@"iPad3,1"]) return 3;// @"iPad 3 (WiFi)"; if ([platform isEqualToString:@"iPad3,2"]) return 3;// @"iPad 3 (GSM+CDMA)"; if ([platform isEqualToString:@"iPad3,3"]) return 3;// @"iPad 3 (GSM)"; if ([platform isEqualToString:@"iPad3,4"]) return 4;// @"New iPad (WiFi)"; if ([platform isEqualToString:@"iPad3,5"]) return 4;// @"New iPad (GSM)"; if ([platform isEqualToString:@"iPad3,6"]) return 4;// @"New iPad (GSM+CDMA)"; if ([platform isEqualToString:@"iPad4,1"]) return 5;// @"iPad Air (WiFi)"; if ([platform isEqualToString:@"iPad4,2"]) return 5;// @"iPad Air (Cellular)"; if ([platform isEqualToString:@"iPad4,4"]) return 5;// @"iPad mini Retina (WiFi)"; if ([platform isEqualToString:@"iPad4,4"]) return 5;// @"iPad mini Retina (Cellular)"; /* Simulator */ if ([platform isEqualToString:@"i386"]) return 3;// @"Simulator"; return 0; }
# 체크 사항
현재 위의 코드를 실행하면 Implicit declaration of function ‘sysctlbyname’ is invalid in C99 이라는 warning이 발생하지만 실행에는 문제가 없음.
[참고] http://theiphonewiki.com/wiki/Models
No. | Category | Subject | Author | Date | Views |
---|---|---|---|---|---|
897 | Develop |
[js] jQuery 셀 병합
1 ![]() |
hooni | 2014.09.23 | 3567 |
896 | Database | [mysql] 중복데이터 삭제하는 초간단 쿼리 | hooni | 2017.11.22 | 3572 |
895 | System/OS |
[android] 초간단 HTTP, POST 전송 샘플
1 ![]() |
hooni | 2017.02.16 | 3659 |
894 | Etc |
영어. 불규칙 동사 정리
![]() |
hooni | 2017.10.04 | 3674 |
893 | Develop | [ios] 유용한 매크로 | hooni | 2014.03.26 | 3703 |
892 | Develop | [ios] UIWebView 캐쉬 삭제 | hooni | 2014.04.08 | 3712 |
891 | Develop | [ios] URL 파라미터 파싱~ | hooni | 2014.05.12 | 3742 |
890 | Develop |
[ios] SQLite 사용하기(튜토리얼) + 샘플코드
![]() |
hooni | 2014.03.28 | 3755 |
» | Develop | [ios] iOS에서 디바이스 종류 알아오기 | hooni | 2014.05.24 | 3764 |
888 | Develop |
[ios] iOS 의 인앱구매 소개
![]() |
hooni | 2014.04.29 | 3905 |
887 | Develop |
[php] 3 Ways to Detect Mobile or Desktop in PHP
![]() |
hooni | 2020.01.28 | 3999 |
886 | Develop | [ios] UDID 사용 제한에 따른 대안들 | hooni | 2014.03.13 | 4024 |