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:@"取消" 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];

如果帮到了你,记得朝着北京海淀西二旗的方向默默的心里喊一声:谢谢博主!

你可能感兴趣的:(iOS开发)