【问题标题】:How to find iPhone/iPod Device model (3G,3GS,4,4S) by code? [duplicate]如何通过代码查找 iPhone/iPod 设备型号(3G、3GS、4、4S)? [复制]
【发布时间】:2012-01-15 15:00:50
【问题描述】:

可能重复:
Determine device (iPhone, iPod Touch) with iOS

我已尝试获取当前设备型号名称,例如 3G、3GS、4、4S、iPodTouch(不同代)。但是,直到现在我还不能得到确切的结果。你能帮我找出设备型号吗?在这里我附上了我用来获取设备型号的代码。

UIDevice *device = [UIDevice currentDevice];
NSString *deviceVersion = [device systemVersion];//Return 4.0.1 and 5.0.1
NSString *deviceName = [device systemName];//Return iPhone, iPod Touch

如何获取设备型号 3G,3GS,4,4S,iPod Touch,iPad?

【问题讨论】:

标签: iphone model ipod-touch


【解决方案1】:
#import <sys/utsname.h>

NSString*
machineName()
{
    struct utsname systemInfo;
    uname(&systemInfo);

    return [NSString stringWithCString:systemInfo.machine
                              encoding:NSUTF8StringEncoding];
}

结果应该是:

@"i386"      on the simulator
@"iPod1,1"   on iPod Touch
@"iPod2,1"   on iPod Touch Second Generation
@"iPod3,1"   on iPod Touch Third Generation
@"iPod4,1"   on iPod Touch Fourth Generation
@"iPhone1,1" on iPhone
@"iPhone1,2" on iPhone 3G
@"iPhone2,1" on iPhone 3GS
@"iPad1,1"   on iPad
@"iPad2,1"   on iPad 2
@"iPhone3,1" on iPhone 4
@"iPhone4,1" on iPhone 4S

【讨论】:

  • 谢谢尼廷先生。您的代码运行得非常完美,符合我的预期。非常感谢。
  • 新模型更新。 iPhone 5(白色)上的 iPhone5,2 和 iPhone 5s(金色)上的 iPhone6,2 来自我自己的设备。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-05-15
  • 1970-01-01
  • 1970-01-01
  • 2018-02-08
相关资源
最近更新 更多