iOS 撥打電話四種方式總結(推薦最後一種)
方法一:不彈出提示直接撥打
NSMutableString *str=[[NSMutableStringalloc]initWithFormat:@"tel:%@",@"電話號碼"];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
方法二:會彈出提示
NSMutableString *str=[[NSMutableStringalloc]initWithFormat:@"tel:%@",@"電話號碼"];
UIWebView *callWebview = [[UIWebViewalloc]init];
[callWebviewloadRequest:[NSURLRequestrequestWithURL:[NSURLURLWithString:str]]];
[self.view addSubview:callWebview];
方法三:會彈出提示
NSMutableString* str=[[NSMutableString alloc]initWithFormat:@"telprompt://%@",@"111"];
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:str]];
以上是正常的三種撥號方式,會有卡頓,網路上好多都是這種答案。
博主機智的想到了如何不讓其卡頓,使用者體驗完美的方案:
方案四之終極撥號方式:
NSMutableString *str=[[NSMutableString alloc]initWithFormat:@"tel:%@“,@“114”];
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:tel preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消
}];
UIAlertAction *otherAction = [UIAlertAction actionWithTitle:@"呼叫" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
}];
// Add the actions.
[alertController addAction:cancelAction];
[alertController addAction:otherAction];
[self presentViewController:alertController animated:YES completion:nil];
如果幫到了你,記得朝著北京海淀西二旗的方向默默的心裡喊一聲:謝謝博主!