2009-04-16 3 views
10

내 응용 프로그램을 사용하여 iPhone의 일련 번호를 알고 싶습니다. 아래에 코드를 작성했습니다.프로그래밍 방식으로 iPhone의 일련 번호를 어떻게 얻습니까?

- (NSString*)getSerialNumber 
{ 
CFTypeRef serialNumberAsCFString; 

io_service_t platformExpert = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching("IOPlatformExpertDevice")); 

if (platformExpert) 
{ 
    serialNumberAsCFString = IORegistryEntryCreateCFProperty(platformExpert, CFSTR(kIOPlatformUUIDKey), kCFAllocatorDefault, 0); 
} 

IOObjectRelease(platformExpert); 

NSString *serial = [[NSString alloc] initWithFormat:@"%@",serialNumberAsCFString]; 

    NSLog(@"serail no==>%@",serialNumberAsCFString); 
    NSLog(@"serail no==>%@",serial); 
} 

왜 여전히 일련 번호가 잘못 되나요?

+1

"잘못된 일련 번호"란 무엇입니까? 그것은 나타나지 않거나 틀린가? –

+0

일련 번호 또는 UUID가 필요합니까? Apple 문서에 따르면 UUID는 모든 장치에서 고유하므로 장치 일련 번호 대신 해당 번호를 사용해야합니다. – balexandre

+1

은 Apple Store에서 허용합니까? – iKT

답변

2

IOKit 프레임 워크를 연결하고 있습니까?

당신은 또한 예를 들어 기타 유용한 정보 를 검색 할 수 UIDevice 클래스를 사용할 수 있습니다

http://blogs.oreilly.com/iphone/2008/08/retrieving-device-information.html

에서 사용할 수있는

id getValue(NSString *iosearch); 

기능을 시도 할 수있다 :

NSString *id = [[UIDevice currentDevice] uniqueIdentifier]; 

기타 용도 UL의 속성은 다음과 같은 것들이다 :

name 
    systemName  
    systemVersion 
    model 
    localizedModel 
+0

ok이 코드를 사용해 보았지만 응용 프로그램이 부적절하게 종료되었고 3 곳에서 경고 메시지가 나타납니다 : 1) CFTypeId propID = NULL; (캐스트없이 포인터) 2) CFTypeRef 소품 = IORegistryEntrySearchCFProperty (항목, \t \t \t \t \t \t \t \t \t \t \t \t \t kIODeviceTreePlane, iosearch, 전무, \t \t \t \t \t \t \t \t \t \t \t \t \t kIORegistryIterateRecursively); (경고 : 인수 전달 호환되지 않는 포인터 유형 에서 'IORegistryEntrySearchCFProperty'중 3 개) –

5

당신은 CFSTR (kIOPlatformSerialNumberKey)CFSTR (kIOPlatformUUIDKey)에서 IORegistryEntryCreateCFProperty의 인수 2를 변경해야합니다. 그런 다음 올바른 일련 번호 (길이는 11 자)를 얻습니다.

0

UIDevice에서 바로 사용할 수있는 카테고리 : UIDevice+serialNumber. 이것이 App Store에서 받아 들여지지 않을지 확신하지 못합니다.

관련 문제