之前做直播教育的項(xiàng)目中,低版本設(shè)備的直播效果很差(例如:iPhone6,iPad2),所以要檢測客戶設(shè)備的版本。
以下代碼檢測 iPhone 6以后出的設(shè)備(不包括iPhone SE)正常使用虐先,iPad是2013年之后出的設(shè)備正常使用。記得要導(dǎo)入頭文件"sys/utsname.h"
派敷。
+ (BOOL)deviceAvailable {
struct utsname systemInfo;
uname(&systemInfo);
///獲得設(shè)備類型(例:"iPad4,5" 或者 "iPhone7,1")
NSString *platform = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
///拆分成數(shù)組(例:["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及以后出的設(shè)備正常
*/
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年之前的提示設(shè)備版本過低
*/
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;
}