programing

특정 iPhone/iPod Touch 모델 탐지

starjava 2023. 6. 6. 00:22
반응형

특정 iPhone/iPod Touch 모델 탐지

중복 가능성:
iOS가 탑재된 장치(iPhone, iPod Touch) 확인

저는 아이폰(아마도 아이팟 터치 2세대)의 피어투피어 블루투스 기능을 활용하는 게임을 만들고 있습니다.하지만, 사용자들이 아이팟 1세대와 아이폰 2G에서 멀티플레이어를 하려고 하는 것을 막으려면 특정 장치 모델을 확인해야 합니다.

[UIDevice currentDevice] 모델에서는 장치가 "iPhone"인지 "iPod touch"인지만 알려줍니다."아이폰 3GS", "아이팟 터치 1세대" 등 특정 장치 모델을 확인할 수 있는 방법이 있습니까?

편집:

UID Device에는 다음 코드를 사용하여 특정 장치 모델을 가져오는 범주가 있습니다(에리카 사둔이 만든 것 같습니다, 저는 그것을 인정하지 않습니다).다른 유용한 자료와 함께 전체 범주를 여기에서 찾을 수 있습니다. https://github.com/erica/uidevice-extension

#include <sys/types.h>
#include <sys/sysctl.h>

@implementation UIDevice (Hardware)

/*
 Platforms
 iPhone1,1 -> iPhone 1G
 iPhone1,2 -> iPhone 3G 
 iPod1,1   -> iPod touch 1G 
 iPod2,1   -> iPod touch 2G 
*/

- (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 stringWithCString:machine encoding:NSUTF8StringEncoding];
  free(machine);
  return platform;
}

이 작업 및 이를 사용하는 앱은 최근 AppStore에서 승인되었습니다.

다음을 사용하여 장치 모델 번호를 얻을 수 있습니다.uname부터sys/utsname.h예:

#import <sys/utsname.h>

NSString*
machineName()
{
    struct utsname systemInfo;
    uname(&systemInfo);

    return [NSString stringWithCString:systemInfo.machine
                              encoding:NSUTF8StringEncoding];
}

결과는 다음과 같습니다.

@시뮬레이터의 "i386"@iPod Touch의 "iPod1,1"@iPod Touch 2세대에서 "iPod 2,1" 사용@iPod Touch 3세대에서 "iPod 3,1" 사용@iPod Touch 4세대에서 "iPod 4,1" 사용@iPhone 1,1"의 iPhone@아이폰 3G의 "아이폰1,2"@아이폰 3GS의 "아이폰2,1"@iPad의 "iPad1,1"@iPad2의 "iPad2,1"@iPad 3에서 "iPad 3,1"(일명 새 iPad)@아이폰4의 "아이폰3,1"@아이폰4S의 "아이폰4,1"@아이폰5의 "아이폰5,1"@아이폰5의 "아이폰5,2"

가장 완벽한 UID 장치(하드웨어) 범주는 아마도 http://github.com/erica/uidevice-extension/ (에리카 사둔)일 것입니다.

[[UIDevice currentDevice] platformType]   // ex: UIDevice4GiPhone
[[UIDevice currentDevice] platformString] // ex: @"iPhone 4G"

이 코드는 어떻습니까, 만약 새로운 버전이 출시되었다면, 당신은 마지막으로 알려진 장치로 식별할 것입니다.

#include <sys/types.h>
#include <sys/sysctl.h>

- (NSString *)getModel {
    size_t size;
    sysctlbyname("hw.machine", NULL, &size, NULL, 0);
    char *model = malloc(size);
    sysctlbyname("hw.machine", model, &size, NULL, 0);
    NSString *sDeviceModel = [NSString stringWithCString:model encoding:NSUTF8StringEncoding];
    free(model);                              
    if ([sDeviceModel isEqual:@"i386"])      return @"Simulator";  //iPhone Simulator
    if ([sDeviceModel isEqual:@"iPhone1,1"]) return @"iPhone1G";   //iPhone 1G
    if ([sDeviceModel isEqual:@"iPhone1,2"]) return @"iPhone3G";   //iPhone 3G
    if ([sDeviceModel isEqual:@"iPhone2,1"]) return @"iPhone3GS";  //iPhone 3GS
    if ([sDeviceModel isEqual:@"iPhone3,1"]) return @"iPhone4 AT&T";  //iPhone 4 - AT&T
    if ([sDeviceModel isEqual:@"iPhone3,2"]) return @"iPhone4 Other";  //iPhone 4 - Other carrier
    if ([sDeviceModel isEqual:@"iPhone3,3"]) return @"iPhone4";    //iPhone 4 - Other carrier
    if ([sDeviceModel isEqual:@"iPhone4,1"]) return @"iPhone4S";   //iPhone 4S
    if ([sDeviceModel isEqual:@"iPhone5,1"]) return @"iPhone5";    //iPhone 5 (GSM)
    if ([sDeviceModel isEqual:@"iPod1,1"])   return @"iPod1stGen"; //iPod Touch 1G
    if ([sDeviceModel isEqual:@"iPod2,1"])   return @"iPod2ndGen"; //iPod Touch 2G
    if ([sDeviceModel isEqual:@"iPod3,1"])   return @"iPod3rdGen"; //iPod Touch 3G
    if ([sDeviceModel isEqual:@"iPod4,1"])   return @"iPod4thGen"; //iPod Touch 4G
    if ([sDeviceModel isEqual:@"iPad1,1"])   return @"iPadWiFi";   //iPad Wifi
    if ([sDeviceModel isEqual:@"iPad1,2"])   return @"iPad3G";     //iPad 3G
    if ([sDeviceModel isEqual:@"iPad2,1"])   return @"iPad2";      //iPad 2 (WiFi)
    if ([sDeviceModel isEqual:@"iPad2,2"])   return @"iPad2";      //iPad 2 (GSM)
    if ([sDeviceModel isEqual:@"iPad2,3"])   return @"iPad2";      //iPad 2 (CDMA)

    NSString *aux = [[sDeviceModel componentsSeparatedByString:@","] objectAtIndex:0];

//If a newer version exist
    if ([aux rangeOfString:@"iPhone"].location!=NSNotFound) {
        int version = [[aux stringByReplacingOccurrencesOfString:@"iPhone" withString:@""] intValue];
        if (version == 3) return @"iPhone4"
        if (version >= 4) return @"iPhone4s";

    }
    if ([aux rangeOfString:@"iPod"].location!=NSNotFound) {
        int version = [[aux stringByReplacingOccurrencesOfString:@"iPod" withString:@""] intValue];
        if (version >=4) return @"iPod4thGen";
    }
    if ([aux rangeOfString:@"iPad"].location!=NSNotFound) {
        int version = [[aux stringByReplacingOccurrencesOfString:@"iPad" withString:@""] intValue];
        if (version ==1) return @"iPad3G";
        if (version >=2) return @"iPad2";
    }
    //If none was found, send the original string
    return sDeviceModel;
}
BOOL hasHighResScreen = NO;
if ([UIScreen instancesRespondToSelector:@selector(scale)]) {
    CGFloat scale = [[UIScreen mainScreen] scale];
    if (scale > 1.0) {
        hasHighResScreen = YES;
    }
}

아이폰4는 아이폰3,1과 아이폰3,2입니다.
iPhone4S는 iPhone4,
버전(GSM 등)에 따라 iPad2,1 iPad2,2 및 iPad2,3입니다.
버전(GSM 등)에 따라 iPad3,1 iPad3,2 및 iPad3,3입니다.

아이폰 비밀 참조("내부 제품 코드"로 스크롤)

또 다른 좋은 소식통은 everyiphone.com 입니다.

NSString* valueDevice = [[UIDevice currentDevice] model];

그런 다음 문자열이 찾고 있는 장치와 동일한지 확인합니다.

if(value==@"iPod1,1" ) 
{}

그리고 당신은 가도 좋습니다.

언급URL : https://stackoverflow.com/questions/1108859/detect-the-specific-iphone-ipod-touch-model

반응형