/ Published in: Objective C

Here is how to determine the device type.\r\n\r\nHow to use it.\r\n\r\nUIDeviceHardware *h=[[UIDeviceHardware alloc] init];\r\n[self setDeviceModel:[h platformString]]; \r\n[h release];
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
// // UIDeviceHardware.h // // Used to determine EXACT version of device software is running on. #import <Foundation/Foundation.h> @end // // UIDeviceHardware.m // // Used to determine EXACT version of device software is running on. #import "UIDeviceHardware.h" #include <sys/types.h> #include <sys/sysctl.h> @implementation UIDeviceHardware size_t size; sysctlbyname("hw.machine", NULL, &size, NULL, 0); sysctlbyname("hw.machine", machine, &size, NULL, 0); return platform; } if ([platform isEqualToString:@"iPhone1,1"]) return @"iPhone 1G"; if ([platform isEqualToString:@"iPhone1,2"]) return @"iPhone 3G"; if ([platform isEqualToString:@"iPhone2,1"]) return @"iPhone 3GS"; if ([platform isEqualToString:@"iPhone3,1"]) return @"iPhone 4"; if ([platform isEqualToString:@"iPod1,1"]) return @"iPod Touch 1G"; if ([platform isEqualToString:@"iPod2,1"]) return @"iPod Touch 2G"; if ([platform isEqualToString:@"iPod3,1"]) return @"iPod Touch 3G"; if ([platform isEqualToString:@"i386"]) return @"iPhone Simulator"; return platform; } @end
URL: http://stackoverflow.com/questions/448162/determine-device-iphone-ipod-touch-with-iphone-sdk
Comments
