我有以下代码
@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]);
Run Code Online (Sandbox Code Playgroud)
我得到的输出为:
Platforms:
-----------
iPhone1,1
iPhone1,2
iPod1,1
iPod2,1
Run Code Online (Sandbox Code Playgroud)
在iphone/ipod touch之后附加的两个数字表示i,e(1,1),(1,2)等?
谢谢Biranchi
iPhone1,1:iPhone(原装)
iPhone1,2:iPhone 3G
iPhone2,1:iPhone 3GS
iPhone3,1:iPhone 4
iPhone4,1:iPhone 4S
iPod1,1:iPod touch(原装)
iPod2,1:iPod touch(第2代)
iPod3,1:iPod touch(第3代)
iPod4,1:iPod touch(第4代)
iPad1,1:iPad(原装)
iPad2,1:iPad 2
iPad3,1:iPad(第3代)