2009-04-16 10 views
10

Quiero saber el número de serie de mi iPhone usando mi aplicación. He escrito el código a continuación.¿Cómo obtiene programáticamente el número de serie de un 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); 
} 

¿Por qué sigo obteniendo el número de serie incorrecto?

+1

¿Qué quiere decir "número de serie incorrecto"? ¿No está apareciendo, o simplemente es incorrecto? –

+0

¿necesita el número de serie o el UUID? Los documentos de Apple dicen que el UUID es único entre todos los dispositivos y que debes usar ese número en lugar del Número de serie del dispositivo. – balexandre

+1

¿eso es aceptado por Apple Store? – iKT

Respuesta

2

¿Está enlazando el marco IOKit?

Pruebe la función

id getValue(NSString *iosearch); 

, disponible en

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

También puede utilizar la clase UIDevice para recuperar otra información útil Por ejemplo, se puede hacer:

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

Otro usef ul propiedades son las siguientes:

name 
    systemName  
    systemVersion 
    model 
    localizedModel 
+0

ok He intentado este código, pero mi aplicación ha finalizado incorrectamente y me da advertencias en 3 lugares: 1) CFTypeId propID = NULL; (Puntero sin el molde) 2) CFTypeRef prop = IORegistryEntrySearchCFProperty (entrada, \t \t \t \t \t \t \t \t \t \t \t \t \t kIODeviceTreePlane, iosearch, nil, \t \t \t \t \t \t \t \t \t \t \t \t \t kIORegistryIterateRecursively); (advertencia: pasar argumento 3 de 'IORegistryEntrySearchCFProperty' del tipo de puntero incompatible ) –

5

debe cambiar el argumento 2 de IORegistryEntryCreateCFPropertyCFSTR (kIOPlatformUUIDKey)-CFSTR (kIOPlatformSerialNumberKey). Luego obtendrá el número de serie correcto (con una longitud de 11 caracteres).

0

Categoría de listo para usar en UIDevice: UIDevice+serialNumber. No estoy seguro de que esto sea aceptado en la App Store.

Cuestiones relacionadas