iPhone设备代

iPhone设备代,iphone,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,

我有以下代码

@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/ipodtouch后面的两个数字表示什么,即(1,1)、(1,2)等

谢谢
比兰奇

硬件修订版。将其视为平台的一个版本。您也可以从以下网站获得此信息:;你为什么这么低调

试试这个:

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

…等

iPhone 1,1:iPhone(原版)
iPhone 1,2:iPhone 3G
iPhone 2,1:iPhone 3GS
iPhone3,1:iPhone4
iPhone 4,1:iPhone 4S

iPod1,1:iPod touch(原版)
iPod 2,1:iPod touch(第二代)
iPod3,1:iPodtouch(第三代)
iPod4,1:iPodtouch(第四代)

iPad1,1:iPad(原版)
iPad2,1:iPad2

iPad3,1:iPad(第三代)

NSString+stringWithCString
不推荐使用,您应该改用
NSString+stringWithCString:encoding