如何自动从ios本机应用程序拨打电话号码

时间:2016-12-28 08:43:50

标签: ios iphone

我想拨打ios原生应用中的电话号码

代码是这样的:

NSString *allString = [NSString stringWithFormat:@"tel:%@",phoneNum];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:allString]]

在IOS10.2中,有些人可以直接自动呼叫,但其他人可以进行确认对话。

那么,我该怎么办才能让所有iphone直接自动通话?

1 个答案:

答案 0 :(得分:0)

在viewcontroller中使用

func doPhoneCall(_ number: String?) {

    if var number = number {
        number = number.replacingOccurrences(of: " ", with: "")
        if let phoneCallURL = URL(string:"tel://\(number)")   {
            openURL(phoneCallURL)
        }
    }
}

 func openURL(_ url: URL) {
    let application = UIApplication.shared
    if (application.canOpenURL(url)) {
        application.openURL(url);
    }
}
相关问题