2009-11-11 4 views
3

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

+0

Vous pouvez également utiliser alloca – rpetrich

+0

'NSString + stringWithCString' est obsolète, vous devez utiliser' NSString + stringWithCString: encoding' à la place. – zekel

Répondre

7

iPhone1,1: iPhone (original)
iPhone1,2: iPhone 3G
iPhone2,1: 3GS
iPhone3,1: iPhone 4
iPhone4,1: iPhone 4S

iPod1,1: iPod touch (original)
iPod2,1: iPod touch (2e génération)
iPod3,1: iPod touch (3e génération)
iPod4,1: iPod touch (4e génération)

iPad1,1: iPad (original)
iPad2,1: iPad 2
iPad3,1: iPad (3ème génération)

+0

** • iPhone3,1 **: iPhone 4 – zekel

+0

iPhone4,1: iPhone 4S –

-2

révisions matérielles. Considérez-les comme une version de la plateforme. Vous pouvez également obtenir ces informations auprès de UIDevice; Pourquoi allez-vous si bas niveau?

Essayez ceci:

UIDevice *dev = [UIDevice currentDevice]; 
NSLog(@"Information for device '%@' (UDID '%@')", [dev name], [dev uniqueIdentifier]); 
NSLog(@"Model: %@", [dev model]); 
NSLog(@"OS: %@ version %@", [dev systemName], [dev systemVersion]); 

... etc.

Questions connexes