Monday, November 5, 2012

Getting device model number whether its iPhone 4 or iPhone 4S etc.,

We have to use C method since there is no NS method to get this information.
snippet of code goes like this:

#import <sys/utsname.h>
struct utsname *sysInfo;
int uname(&sysInfo);

    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
@"iPad3,1"   on iPad 3 (aka new iPad)
@"iPhone3,1" on iPhone 4
@"iPhone4,1" on iPhone 4S
@"iPhone5,1" on iPhone 5
@"iPhone5,2" on iPhone 5
The structure utsname is declared in <sys/utsname.h> and has the following elements:
 char *sysname;
points to the name of the operating system implementation.
 char *nodename;
points to the node name within a communications network for the specific implementation.
 char *release;
points to the current release level for the implementation.
 char *version;
points to the current version number for the release.
 char *machine;
points to the name of the machine on which the operating system is running.

uname stores information about operating system you are running under in a structure pointed to by sysInfo.

 uname returns a nonnegative value if successful and a -1 if unsuccessful.
 The following example illustrates the use of uname to determine information about the operating system:

#include <systypes.h>
#include <sys/utsname.h>
#include <stdio.h>

main()
{
   struct utsname sysInfo;

   if (uname(&sysinfo) != -1) {
      puts(sysInfo.sysname);
      puts(sysInfo.nodename);
      puts(sysInfo.release);
      puts(sysInfo.version);
      puts(sysInfo.machine);
   }
   else
      perror("uname() error");
}

Refer:
1.http://support.sas.com/documentation/onlinedoc/sasc/doc750/html/lr2/zid-9810.htm
2.http://stackoverflow.com/questions/1108859/detect-the-specific-iphone-ipod-touch-model

No comments:

Post a Comment