iOS 通讯录拨打电话

拨打电话总共有三种方式,稍微有点区别的就是拨打完电话是回到我们的应用,还是停留在手机通讯录界面,还有一个区别就是在于是否有弹出框提醒;
1.第一种拨打电话完电话不会回到我们的应用,而是直接停留在手机通讯录中,并且没有提示直接拨打电话;

    NSString * mobileStr =[NSString stringWithFormat:@"tel:%@",@"0571-xxxx2128"];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:mobileStr]];

注:如果想要有弹出框的话,我们可以自己加一个弹出框(在xocde7里面使用UIAlertController弹出框)。
如果想要中间弹出的就使用UIAlertControllerStyleAlert;如果想要下面弹出的就使用UIAlertControllerStyleActionSheet;

 /*另一种拨打电话方式
//    UIAlertController * alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"是否要拨打电话" preferredStyle:UIAlertControllerStyleAlert];
//    UIAlertAction * okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//          NSString * mobileStr =[NSString stringWithFormat:@"tel:%@",@"0571-81022128"];
//          [[UIApplication sharedApplication] openURL:[NSURL URLWithString:mobileStr]];
//    }];
//    UIAlertAction * cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
//        
//    }];
//    [alert addAction:okAction];
//    [alert addAction:cancelAction];
//    [self presentViewController:alert animated:YES completion:nil];
     */
码片

2.第二种拨打完电话会回到我们的应用程序,并带有弹出框提示;

    NSMutableString * str=[[NSMutableString alloc] initWithFormat:@"tel:%@",@"0571-xxxx2128"];
    UIWebView * callWebview = [[UIWebView alloc] init];
    [callWebview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str]]];
    [self.view addSubview:callWebview];

3.第三种拨打电话也会有提示并会回到我们的应用程序;

  NSString * mobileStr =[NSString stringWithFormat:@"telprompt://%@",@"0571-xxxx2128"];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:mobileStr]];
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值