之前做直播教育的项目中,低版本设备的直播效果很差(例如:iPhone6,iPad2),所以要检测客户设备的版本。
以下代码检测 iPhone 6以后出的设备(不包括iPhone SE)正常使用,iPad是2013年之后出的设备正常使用。记得要导入头文件"sys/utsname.h"
。
+ (BOOL)deviceAvailable {
struct utsname systemInfo;
uname(&systemInfo);
///获得设备类型(例:"iPad4,5" 或者 "iPhone7,1")
NSString *platform = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
///拆分成数组(例:["ipad4", "5"] 或者 ["iPhone7", "1"])
NSArray *tParagramArray = [platform componentsSeparatedByString:@","];
if ([tParagramArray count]<2) {
return false;
}
///过滤掉英文字母 (例:["", "4"]或者["","7"])
NSString *platString = [tParagramArray objectAtIndex:0];
NSString *m = [tParagramArray objectAtIndex:1];
NSArray *tIPhoneArray = [platString componentsSeparatedByString:@"iPhone"];
NSArray *tIPadArray = [platString componentsSeparatedByString:@"iPad"];
if ([tIPhoneArray count] == 2) {
/*
iPhone n,m
n > 6
n = 8, m = 4 iPhone SE 不适配
iPhone 是 6及以后出的设备正常
*/
NSString *n = [tIPhoneArray objectAtIndex:1];
///iPhoneSE不适配
if ([n intValue] == 8 && [m intValue] == 4){
return NO;
}
BOOL isConformPhone = [n intValue] > 6 ? YES : NO;
if (isConformPhone) return isConformPhone;
}
if ([tIPadArray count] == 2) {
/** iPad
iPad n,m
n > 4
n = 4, m > 6
2013年之前的提示设备版本过低
*/
NSString *n = [tIPadArray objectAtIndex:1];
BOOL isConformIPad = [n intValue] > 4 ? YES : NO;
if (isConformIPad) {
return isConformIPad;
}
if ([n intValue] == 4) {
isConformIPad = [m intValue] > 6 ? YES : NO;
}
return isConformIPad;
}
return NO;
}
网友评论