iOS 10拨打系统电话发现弹出框会延迟2s左右出现,很不爽,研究了一下,发现是openURL在ios 10及其之后会阻塞主线程
所以,拨打电话前,做个判断,来代码,
方案一:
// 拨打电话
+ (void)callPhone:(NSString *)phoneNum {
if (phoneNum.length == 0) {
return;
}
NSString *callPhone = [NSString stringWithFormat:@"telprompt://%@", phoneNum];
NSComparisonResult compare = [[UIDevice currentDevice].systemVersion compare:@"10.0"];
if (compare == NSOrderedDescending || compare == NSOrderedSame) {
/// 大于等于10.0系统使用此openURL方法
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:callPhone] options:@{} completionHandler:nil];
} else {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:callPhone]];
}
}
方案二
// 拨打电话
+ (void)callPhone:(NSString *)phoneNum {
if (phoneNum.length == 0) {
return;
}
NSString *callPhone = [NSString stringWithFormat:@"telprompt://%@", phoneNum];
dispatch_async(dispatch_get_global_queue(0, 0), ^{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:callPhone]];
});
}
关于拨打电话的方法,自己凭喜好选择,导致弹出框延迟的原因,目前初步诊断就是openURL在iOS 10及其之后会阻塞主线程
网友评论