2009-11-11 57 views
3

我有以下代码iPhone设备代

@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]); 

我得到的输出:

Platforms: 
----------- 
iPhone1,1 
iPhone1,2 
iPod1,1 
iPod2,1 

什么的iPhone/iPod touch上之后附加两个数字表示I,E(1 ,1),(1,2)等?

感谢 Biranchi

+0

你也可以使用ALLOCA – rpetrich 2009-11-12 09:09:13

+0

'的NSString + stringWithCString'已过时,你应该使用'的NSString + stringWithCString:encoding'代替。 – zekel 2010-11-21 01:40:06

回答

7

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

iPod1,1:iPod touch(original)
iPod2,1:iPod touch(第二代)
iPod3,1:iPod touch(第三代)
iPod4,1:的iPod touch(第4代)

iPad1,1:ipad公司(原)
iPad2,1:iPad 2的
iPad3,1:ipad公司(第3代)

+0

**•iPhone3,1 **:iPhone 4 – zekel 2011-08-26 15:07:16

+0

iPhone4,1:iPhone 4S – 2012-04-24 18:36:59

-2

硬件版本。将它们视为平台的一个版本。您也可以从UIDevice获取此信息;你为什么这么低级?

试试这个:

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

...等。