美文网首页iOS 技术分享iOS Developer
iOS 拨打电话 弹框延迟出现

iOS 拨打电话 弹框延迟出现

作者: Joh蜗牛 | 来源:发表于2017-06-16 17:06 被阅读112次

    iOS 10拨打系统电话发现弹出框会延迟2s左右出现,很不爽,研究了一下,发现是openURL在http://blog.csdn.net/syg90178aw/article/details/68926603及其之后会阻塞主线程

    所以,拨打电话前,做个判断,来代码,

    方案一:

    // 拨打电话

    + (void)callPhone:(NSString*)phoneNum {

    if(phoneNum.length==0) {

    return;

    }

    NSString*callPhone = [NSStringstringWithFormat:@"telprompt://%@",phoneNum];

    NSComparisonResult compare = [[UIDevicecurrentDevice].systemVersioncompare:@"10.0"];

    if(compare == NSOrderedDescending || compare == NSOrderedSame) {

    /// 大于等于10.0系统使用此openURL方法

    [[UIApplicationsharedApplication]openURL:[NSURLURLWithString:callPhone]options:@{}completionHandler:nil];

    }else{

    [[UIApplicationsharedApplication]openURL:[NSURLURLWithString:callPhone]];

    }

    }

    方案二

    // 拨打电话

    + (void)callPhone:(NSString*)phoneNum {

    if(phoneNum.length==0) {

    return;

    }

    NSString*callPhone = [NSStringstringWithFormat:@"telprompt://%@",phoneNum];

    dispatch_async(dispatch_get_global_queue(0,0), ^{

    [[UIApplicationsharedApplication]openURL:[NSURLURLWithString:callPhone]];

    });

    }

    关于拨打电话的方法,自己凭喜好选择,导致弹出框延迟的原因,目前初步诊断就是openURL在iOS 10及其之后会阻塞主线程

    原文:http://blog.csdn.net/syg90178aw/article/details/68926603

    相关文章

      网友评论

        本文标题:iOS 拨打电话 弹框延迟出现

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