How to find iPhone/iPod Device model(3G,3GS,4,4S) by code?

Possible Duplicate:
Determine device (iPhone, iPod Touch) with iPhone SDK

I have tried to get the current device model name like 3G,3GS,4,4S,iPodTouch(Different Generations). But, i cant 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

How can i get the device model 3G,3GS,4,4S,iPod Touch,iPad? Thanks in advance.


#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

There is a library on girhub that will do it. See this link:

https://github.com/erica/uidevice-extension

链接地址: http://www.djcxy.com/p/8892.html

上一篇: 使用HTML / JavaScript获取iPhone设备详细信息

下一篇: 如何通过代码找到iPhone / iPod设备型号(3G,3GS,4,4S)?