iOS 实现拨打电话功能

我需要实现拨打电话,但是使用网上的代码点击后毫无反应,为什么?
NSMutableString * str=[[NSMutableString alloc] initWithFormat:@"tel:%@",@"137********"];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];

UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"400-820-8820" message:nil preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

    }];
    UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { NSMutableString  * str = [[NSMutableString alloc] initWithFormat:@"tel:%@",@"4400-820-8820"];
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
    }];

    [alertController addAction:cancelAction];
    [alertController addAction:okAction];
    [self presentViewController:alertController animated:YES completion:nil];

先断点看代码有没有走到这里,再看是不是别的UI覆盖掉了你的弹窗,再看看头文件包进去了没,最后检查一下IOS是不是关闭了游戏内调用Phone功能,都不是换一套代码,我记得有三种。

不懂顶一个,我要去下载东西露

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

注意这里的telprompt!!!改为这个就可以了,亲测

http://blog.csdn.net/wujakf/article/details/72722814
这里有你想要的,还有就是拨打电话的弹窗会有延迟。

http://blog.csdn.net/syg90178aw/article/details/68926603
这个可以看一哈,既有拨打电话的方法,也有解决弹出框延迟

由于现在是iOS 11出来了 楼上的方法废弃了 现在改成了
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"tel://%@",186xxxxxxxx]];
[[UIApplication sharedApplication] openURL:url options:@{UIApplicationOpenURLOptionsSourceApplicationKey : @YES} completionHandler:nil];