admin 管理员组文章数量: 1086019
iOS 拨打电话
第一种
NSString *phoneStr = [NSString stringWithFormat:@"tel://%@",phone];
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 10.0) {//设备系统为IOS 10.0或者以上的[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneStr] options:@{} completionHandler:nil];
}else{//设备系统为IOS 10.0以下的[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneStr]];
if (@available(iOS 10.0, *)) {//设备系统为IOS 10.0或者以上的[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneStr] options:@{} completionHandler:nil];
} else {[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneStr]];
}
第二种
NSString *phoneStr = [NSString stringWithFormat:@"tel:%@",phone];
UIWebView * callWebview = [[UIWebView alloc] init];
[callWebview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:phoneStr]]];
[self.view addSubview:callWebview];
但是 webView
已经不能使用了,要换 WKWebView
第一步
#import <WebKit/WebKit.h>@interface ViewController ()<WKNavigationDelegate>
第二步
WKWebView *webView = [WKWebView new];
webView.navigationDelegate = self;
NSString *phoneStr = [NSString stringWithFormat:@"tel:%@",self.model.store.contactPhone];
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:phoneStr]]];
[self.view addSubview:webView];
第三步
- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {NSURL *URL = navigationAction.request.URL;NSString *scheme = [URL scheme];UIApplication *app = [UIApplication sharedApplication];// 打电话if ([scheme isEqualToString:@"tel"]) {if ([app canOpenURL:URL]) {[app openURL:URL];// 一定要加上这句,否则会打开新页面decisionHandler(WKNavigationActionPolicyCancel);return;}}decisionHandler(WKNavigationActionPolicyAllow);
}
第三种
NSString *telephoneNumber=@"拨打的号码";
NSMutableString * str=[[NSMutableString alloc] initWithFormat:@"telprompt://%@",telephoneNumber];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]]
本文标签: iOS 拨打电话
版权声明:本文标题:iOS 拨打电话 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.roclinux.cn/b/1686729440a30193.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论