導入#import
/**
* iPhone的設備號
**/
+ (NSString *)iPhoneVersion
{
NSString *iPhoneVersion = nil;
size_t size;
sysctlbyname(hw.machine, NULL, &size, NULL, 0);
char *machine = (char*)malloc(size);
sysctlbyname(hw.machine, machine, &size, NULL, 0);
NSString *platform = [NSString stringWithCString:machine encoding:NSUTF8StringEncoding];
free(machine);
if ([platform isEqualToString:@iPhone1,1]) {
iPhoneVersion = @iPhone;
}
if ([platform isEqualToString:@iPhone1,2]) {
iPhoneVersion = @iPhone 3G;
}
if ([platform isEqualToString:@iPhone2,1]) {
iPhoneVersion = @iPhone 3GS;
}
if ([platform isEqualToString:@iPhone3,1] || [platform isEqualToString:@iPhone3,2] || [platform isEqualToString:@iPhone3,3]) {
iPhoneVersion = @iPhone 4;
}
if ([platform isEqualToString:@iPhone4,1]) {
iPhoneVersion = @iPhone 4S;
}
if ([platform isEqualToString:@iPhone5,1] || [platform isEqualToString:@iPhone5,2]) {
iPhoneVersion = @iPhone 5;
}
if ([platform isEqualToString:@iPhone5,3] || [platform isEqualToString:@iPhone5,4]) {
iPhoneVersion = @iPhone 5c;
}
if ([platform isEqualToString:@iPhone6,1] || [platform isEqualToString:@iPhone6,2]) {
iPhoneVersion = @iPhone 5s;
}
if ([platform isEqualToString:@iPhone7,2]) {
iPhoneVersion = @iPhone 6;
}
if ([platform isEqualToString:@iPhone7,1]) {
iPhoneVersion = @iPhone 6Plus;
}
return iPhoneVersion;
}