ios10以后调用电话太慢

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]];  
    });  
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容