- (NSString *)getModel {
size_t size;
sysctlbyname("hw.machine", NULL, &size, NULL, 0);
char *model = malloc(size);
sysctlbyname("hw.machine", model, &size, NULL, 0);
NSString *sDeviceModel = [NSString stringWithCString:model encoding:NSUTF8StringEncoding];
free(model);
if ([sDeviceModel isEqual:@"i386"]) return @"Simulator"; //iPhone Simulator
if ([sDeviceModel isEqual:@"iPhone1,1"]) return @"iPhone1G"; //iPhone 1G
if ([sDeviceModel isEqual:@"iPhone1,2"]) return @"iPhone3G"; //iPhone 3G
if ([sDeviceModel isEqual:@"iPhone2,1"]) return @"iPhone3GS"; //iPhone 3GS
if ([sDeviceModel isEqual:@"iPhone3,1"]) return @"iPhone4"; //iPhone 4 - AT&T
if ([sDeviceModel isEqual:@"iPhone3,2"]) return @"iPhone4"; //iPhone 4 - Other carrier
if ([sDeviceModel isEqual:@"iPhone3,3"]) return @"iPhone4"; //iPhone 4 - Verizone
if ([sDeviceModel isEqual:@"iPhone4,1"]) return @"iPhone4S"; //iPhone 4S
if ([sDeviceModel isEqual:@"iPod1,1"]) return @"iPod1stGen"; //iPod Touch 1G
if ([sDeviceModel isEqual:@"iPod2,1"]) return @"iPod2ndGen"; //iPod Touch 2G
if ([sDeviceModel isEqual:@"iPod3,1"]) return @"iPod3rdGen"; //iPod Touch 3Gif ([sDeviceModel isEqual:@"iPod4,1"]) return @"iPod4thGen"; //iPod Touch 4G
if ([sDeviceModel isEqual:@"iPad1,1"]) return @"iPadWiFi"; //iPad Wifi
if ([sDeviceModel isEqual:@"iPad1,2"]) return @"iPad3G"; //iPad 3G
if ([sDeviceModel isEqual:@"iPad2,1"]) return @"iPad2WiFi"; //iPad 2 (WiFi)
if ([sDeviceModel isEqual:@"iPad2,2"]) return @"iPad2GSM"; //iPad 2 (GSM)
if ([sDeviceModel isEqual:@"iPad2,3"]) return @"iPad2CDMA"; //iPad 2 (CDMA)
if ([sDeviceModel isEqual:@"iPad3,1"]) return @"iPad3GWiFi"; //iPad 3G (WiFi)
if ([sDeviceModel isEqual:@"iPad3,2"]) return @"iPad3G4G"; //iPad 3G (4G)
if ([sDeviceModel isEqual:@"iPad3,3"]) return @"iPad3G4G"; //iPad 3G (4G)
NSString *aux = [[sDeviceModel componentsSeparatedByString:@","] objectAtIndex:0];
//If a newer version exist
if ([aux rangeOfString:@"iPhone"].location!=NSNotFound) {
int version = [[aux stringByReplacingOccurrencesOfString:@"iPhone" withString:@""] intValue];
if (version == 3) return @"iPhone4";
if (version >= 4) return @"iPhone4s";
}
if ([aux rangeOfString:@"iPod"].location!=NSNotFound) {
int version = [[aux stringByReplacingOccurrencesOfString:@"iPod" withString:@""] intValue];
if (version >=4) return @"iPod4thGen";
}
if ([aux rangeOfString:@"iPad"].location!=NSNotFound) {
int version = [[aux stringByReplacingOccurrencesOfString:@"iPad" withString:@""] intValue];
if (version ==1) return @"iPad3G";
if (version >=2) return @"iPad2";
}
//If none was found, send the original string
return sDeviceModel;
}
@end
'Dev > iOS' 카테고리의 다른 글
CFBundleVersion (1) | 2021.12.14 |
---|---|
[iOS] Application 디렉토리에 있는 파일을 Documents 디렉토리로 복사하는 예제. (0) | 2011.11.04 |
In App Purchase : invalidProductIdentifiers (1) | 2011.01.14 |
App 안에 Store Link 달기 (0) | 2011.01.10 |
[Xcode] Build and Archive (1) | 2010.12.22 |