美文网首页IOS
iOS-拨打电话

iOS-拨打电话

作者: BestVast | 来源:发表于2016-08-18 18:14 被阅读71次

    http://blog.csdn.net/ouy_huan/article/details/30506925 借鉴于此,谢谢
    1、这种方法,打完电话后还会回到原来的程序,也会弹出提示,推荐这种

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

    2、这种方法,挂断电话会在原来的应用,而且是直接拨打,不弹出提示

    NSMutableString * str=[[NSMutableString alloc] initWithFormat:@"tel:%@", @"电话号码"];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
    

    此方法可以自己定义提示信息:

    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:[NSString stringWithFormat:@"拨打该电话按照正常资费由运营商收取:%@", @"182xxxxxxxx"] preferredStyle:UIAlertControllerStyleAlert];
            UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                [alert dismissViewControllerAnimated:YES completion:^{
                    NSLog(@"取消拨打电话");
                }];
            }];
            UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                NSMutableString * str=[[NSMutableString alloc] initWithFormat:@"tel:%@", @"182xxxxxxxx"];
                [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
            }];
            [alert addAction:action1];
            [alert addAction:action2];
            [self presentViewController:alert animated:YES completion:^{
                NSLog(@"弹出拨打电话号码弹框");
            }];
    

    3,这种方法也会回去到原来的程序里(注意这里的telprompt),也会弹出提示

    NSMutableString * str=[[NSMutableString alloc] initWithFormat:@"telprompt://%@", @"182xxxxxxxx"];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
    

    相关文章

      网友评论

        本文标题:iOS-拨打电话

        本文链接:https://www.haomeiwen.com/subject/gbwvsttx.html