iOS笔记之四种拨号方式
2017-12-04 本文已影响15人
SuAdrenine
方法一:不弹出提示直接拨打
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:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
}];
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];