je le code suivantdispositif iPhone génération
@implementation UIDevice(machine)
- (NSString *)machine
{
size_t size;
// Set 'oldp' parameter to NULL to get the size of the data
// returned so we can allocate appropriate amount of space
sysctlbyname("hw.machine", NULL, &size, NULL, 0);
// Allocate the space to store name
char *name = malloc(size);
// Get the platform name
sysctlbyname("hw.machine", name, &size, NULL, 0);
// Place name into a string
NSString *machine = [NSString stringWithCString:name];
// Done with this
free(name);
return machine;
}
@end
/* ... */
NSLog(@"device: %@", [[UIDevice currentDevice] machine]);
Je reçois la sortie comme:
Platforms:
-----------
iPhone1,1
iPhone1,2
iPod1,1
iPod2,1
qu'est-ce que les deux numéros joints après l'iPhone/iPod touch signifient i, e (1 , 1), (1,2) etc?
Merci Biranchi
Vous pouvez également utiliser alloca – rpetrich
'NSString + stringWithCString' est obsolète, vous devez utiliser' NSString + stringWithCString: encoding' à la place. – zekel