您的位置:首页 > 移动开发 > IOS开发

iOS - 拨打电话的方式总结

2017-09-06 11:34 796 查看

拨打电话的方式总结

方式一

用法

/**
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ios 拨打电话