如何通过代码查找 iPhone/iPod 设备型号(3G、3GS、4、4S)? [英] How to find iPhone/iPod Device model (3G,3GS,4,4S) by code?

查看:28
本文介绍了如何通过代码查找 iPhone/iPod 设备型号(3G、3GS、4、4S)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能的重复:
使用 iOS 确定设备(iPhone、iPod Touch)

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

I have tried to get the current device model name like 3G,3GS,4,4S,iPodTouch (Different Generations). But, I can't get an exact result till now. Can you please help me to find out the device model? Here I have attached my code that I used to get device model.

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?

How can I get the device model 3G,3GS,4,4S,iPod Touch,iPad?

推荐答案

#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/iPod 设备型号(3G、3GS、4、4S)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆