7

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

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

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

Cœur
  • 37,241
  • 25
  • 195
  • 267
Gopinath
  • 5,392
  • 21
  • 64
  • 97
  • 3
    There is already a post with a great answer. [Check out Brian Robbins answer here.][1] [1]: http://stackoverflow.com/questions/448162/determine-device-iphone-ipod-touch-with-iphone-sdk – gurooj Dec 08 '11 at 05:34
  • There is a library on GitHub, which can help you https://github.com/erica/uidevice-extension – mip Dec 07 '19 at 23:42

1 Answers1

14
#import <sys/utsname.h>

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

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

The result should be:

@"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
nithin
  • 2,457
  • 1
  • 30
  • 50
  • Thank you Mr.Nithin. Your code running very perfect what i expected. Thanks a lot. – Gopinath Dec 08 '11 at 06:17
  • Update for new models. iPhone5,2 on iPhone 5 (white) and iPhone6,2 on iPhone 5s (gold) from my own devices. – Joey Nov 20 '13 at 06:16