我有以下代码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
你也可以使用ALLOCA – rpetrich 2009-11-12 09:09:13
'的NSString + stringWithCString'已过时,你应该使用'的NSString + stringWithCString:encoding'代替。 – zekel 2010-11-21 01:40:06