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]];

你可能感兴趣的:(拨打电话)