更新时间:2023-10-21 07:53:27
我知道这可能太晚了,无论如何可能都不回答这个问题,但我想'是什么heck' - 确定设备范围是一个很好的代码,在cas中您可能需要不同的功能。
I know it's probably way too late, and probably doesn't answer the question anyway, but I figured 'what the heck' – it's a nice bit of code to determine ranges of devices, where in cases you may want different functionality.
#import <sys/sysctl.h>
-(BOOL)isANewerDevice{
size_t size;
sysctlbyname("hw.machine", NULL, &size, NULL, 0);
char *machine = malloc(size);
sysctlbyname("hw.machine", machine, &size, NULL, 0);
NSString *platform = [NSString stringWithCString:machine encoding:NSUTF8StringEncoding];
free(machine);
NSString * ending = [platform substringFromIndex:[platform length]-3];
double convertedNumber = [[ending stringByReplacingOccurrencesOfString:@"," withString:@"."] doubleValue];
//Devices listed here: https://***.com/questions/19584208/identify-new-iphone-model-on-xcode-5-5c-5s
if ([platform containsString:@"iPhone"]) {
if (convertedNumber >= 7.1) { // 6 and above
return YES;
}else{
return NO; //less than a 6 (ie 5S and below)
}
}else if ([platform containsString:@"iPad"]){
if (convertedNumber >= 5.3) { //iPad Air 2 and above
return YES;
}else{
return NO; //iPad Mini 3 and below
}
}
//Failsafe
return NO;
}
代码中注释的链接:在xcode(5,5c,5s)上识别新的iPhone型号
注意。由于 containsString
,这将在小于8的iOS版本上崩溃。要支持< 8.0,请尝试使用以下代码重新拟合此函数https://***.com/a/26416172/1197723
Note. Due to having containsString
, this will crash on iOS versions less than 8. To support <8.0, try using the following code to retro-fit this function https://***.com/a/26416172/1197723
玩得开心!