iOS OC 判断刘海屏,异形屏,IphoneX
+(BOOL)isNotchScreen{
BOOLisNotchScreen =NO;
if([selfisSimulator]) {
NSString * obj = [[NSProcessInfo processInfo].environment objectForKey:@"SIMULATOR_MODEL_IDENTIFIER"];
isNotchScreen = [selfjudgeIsNotchScreen:obj];
}else{
structutsnamesystemInfo;
uname(&systemInfo);
NSString* phoneType = [NSStringstringWithCString: systemInfo.machineencoding:NSASCIIStringEncoding];
isNotchScreen = [selfjudgeIsNotchScreen:phoneType];
}
returnisNotchScreen;
}
+(BOOL)judgeIsNotchScreen:(NSString*)phoneType{
if (![phoneType isKindOfClass:NSString.class]) {
phoneType = [NSStringstringWithFormat:@"%@", phoneType];
}
if([phoneTypehasPrefix:@"iPhone"]) {
phoneType = [phoneTypesubstringFromIndex:@"iPhone".length];
NSArray* types = [phoneTypecomponentsSeparatedByString:@","];
if(types.count>=2) {
NSString* mainType = types[0];
NSString* subType = types[1];
if(mainType.intValue==10&& (subType.intValue==3|| subType.intValue==6)) { //iPhoneX
returnYES;
}elseif(mainType.intValue==12&& subType.intValue==8){ //iPhoneSE 第二代
returnNO;
}elseif(mainType.intValue>10) {
returnYES;
}
}
}
return NO;
}
+(BOOL)isSimulator
{
if (TARGET_IPHONE_SIMULATOR == 1 && TARGET_OS_IPHONE == 1) {
//模拟器
returnYES;
}else{
//真机
returnNO;
}
}