iOS

来源:互联网 发布:淘宝违法店铺举报 编辑:程序博客网 时间:2024/06/01 09:59

拨打电话的方式总结

方式一

用法

/** cell的自定义代理方法 @param leaveListCell cell @param phone 电话号码 */- (void)leaveListCell:(ZDTLeaveListCell *)leaveListCell phoneCall:(NSString *)phone{    //拨打电话代码    NSMutableString * phoneStr=[[NSMutableString alloc] initWithFormat:@"telprompt://%@",phone];    NSURL *phoneUrl = [NSURL URLWithString:phoneStr];    dispatch_async(dispatch_get_global_queue(0, 0), ^{        if ([LGApplication canOpenURL:phoneUrl]) {            [LGApplication openURL:phoneUrl];        }    });}

效果

这里写图片描述

特点

  • 弹出快, 有提示, 拨打完毕会跳回到拨打前App的界面

方式二

用法

/** cell的自定义代理方法 @param leaveListCell cell @param phone 电话号码 */- (void)leaveListCell:(ZDTLeaveListCell *)leaveListCell phoneCall:(NSString *)phone{    //拨打电话    NSMutableString *str=[[NSMutableString alloc] initWithFormat:@"tel:%@",phone];    UIWebView *callWebview = [[UIWebView alloc] init];    [callWebview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str]]];    [self.view addSubview:callWebview];}

效果

同上

特点

弹出会有1~3s的延迟,有提示,拨打完毕会跳回到拨打前App的界面

方式三

用法

/** cell的自定义代理方法 @param leaveListCell cell @param phone 电话号码 */- (void)leaveListCell:(ZDTLeaveListCell *)leaveListCell phoneCall:(NSString *)phone{    //拨打电话    NSMutableString * phoneStr=[[NSMutableString alloc] initWithFormat:@"tel://%@",phone];    //加不加tel:后面的斜杠都一样    //NSMutableString * phoneStr=[[NSMutableString alloc] initWithFormat:@"tel:%@",phone];    NSURL *phoneUrl = [NSURL URLWithString:phoneStr];    dispatch_async(dispatch_get_global_queue(0, 0), ^{        if ([LGApplication canOpenURL:phoneUrl]) {            [LGApplication openURL:phoneUrl];        }    });}

效果

同上

特点

在iOS10.3上方式三和方式一是一样的.都会跳回原来的App拨打界面,亲测

结论

方式一和方式三比较好,不过考虑到可能出现的兼容问题,推荐方式一.

PS

新blog地址:www.livefor.cn

原创粉丝点击