美文网首页
ios10以后调用电话太慢

ios10以后调用电话太慢

作者: 6灰太狼9 | 来源:发表于2017-05-09 14:24 被阅读124次

    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]];  
        });  
    }
    

    相关文章

      网友评论

          本文标题:ios10以后调用电话太慢

          本文链接:https://www.haomeiwen.com/subject/iqobtxtx.html