方法
- (BOOL)isSuitableMachine:(int)targetPlatNum {
int mib[2] = {CTL_HW, HW_MACHINE};
size_t len = 0;
char *machine;
sysctl(mib, 2, NULL, &len, NULL, 0);
machine = (char *) malloc(len);
sysctl(mib, 2, machine, &len, NULL, 0);
NSString *platform = [NSString stringWithCString:machine encoding:NSASCIIStringEncoding];
NSLog(@"hhhhhhhhhhhhhh======%@",platform);
free(machine);
if ([platform length] > 6) {
NSString *platNum = [NSString stringWithFormat:@"%C", [platform characterAtIndex:6]];
if([platform containsString:@"iPhone"]){
NSArray *array = [platform componentsSeparatedByString:@","];
NSString *str = array[0];
platNum = [str substringWithRange:NSMakeRange(6, str.length-6)];
}
return ([platNum intValue] >= targetPlatNum);
} else {
return NO;
}
}
调用
判断是否是6以上手机
[self isSuitableMachine:7]
判断是否是5以上手机
[self isSuitableMachine:5]
网友评论