简体   繁体   English

swift3 - canOpenURL:URL 电话失败

[英]swift3 - canOpenURL: failed for URL tel

I want to intent a call , this is my code :我想打个电话,这是我的代码:

if let urlMobile = NSURL(string: "tel://076938483"), UIApplication.shared.canOpenURL(urlMobile as URL) {

                if #available(iOS 10.0, *) {
                    UIApplication.shared.open(urlMobile as URL, options: [:], completionHandler: nil)
                }
                else {
                    UIApplication.shared.openURL(urlMobile as URL)
                }
            }

I'm using swift 3 to do so but I get this error:我正在使用 swift 3 来执行此操作,但出现此错误:

-canOpenURL: failed for URL: "tel://09178883828" - error: "The operation couldn’t be completed. (OSStatus error -10814.)"

any idea to do so ?有什么想法吗?

Your code works perfectly fine.您的代码运行良好。 Run it on an actual device if your using Simulator.如果您使用模拟器,请在实际设备上运行它。 You can't simulate a call on a Mac/MacBook.您无法在 Mac/MacBook 上模拟通话。

Please have a look at Simulator Hardware Actions in Apple documentation.请查看 Apple 文档中的Simulator Hardware Actions

Some LSApplicationQueriesScheme do not work on Simulator.某些 LSApplicationQueriesScheme 在模拟器上不起作用。 Error Code -10814 is for kLSApplicationNotFoundErr.错误代码 -10814 用于 kLSApplicationNotFoundErr。 Simulator can't launch Dial Pad for Telephone.模拟器无法启动电话拨号盘 So run it on iPhone device.所以在 iPhone 设备上运行它。

This worked for me!!!这对我有用!!!

Code Should be代码应该是

if let url = NSURL(string: "tel://\(yourNumber)"), UIApplication.shared.canOpenURL(url as URL) {
  UIApplication.shared.open(url as URL, options: [:], completionHandler: nil)
}

网址应该是:

if let urlMobile = NSURL(string: "tel:///076938483"), UIApplication.shared.canOpenURL(urlMobile as URL) {
let phonenumber = "076938483"
guard let url = URL(string: "tel://\(phonenumber )") else {
            return
            
        }
        if #available(iOS 10.0, *) {
            UIApplication.shared.open(url)
        } else {
            UIApplication.shared.openURL(url)
        }

In the else part of the URL generation, print anything, if it is getting printed, you need to check the format of the phone number.在 URL 生成的 else 部分,打印任何内容,如果打印出来,您需要检查电话号码的格式。

@IBAction func Call(_ sender: Any) { @IBAction func Call(_ sender: Any) {

    let busPhone = "7355535586"
    if let url = URL(string: "tel://\(busPhone)"), UIApplication.shared.canOpenURL(url) {
        if #available(iOS 10, *) {
            UIApplication.shared.open(url)
        } else {
            UIApplication.shared.openURL(url)
        }
    }    
@objc func callBtn() {
       let userPhone = String((phoneNum.filter {!" \n\t\r".contains($0)}))
       if let url = URL(string: "tel://\(phoneNum)"), UIApplication.shared.canOpenURL(url) {
           DispatchQueue.main.async {
               UIApplication.shared.open(url)
           }
        }
    }

Note : This code can work when you run with the real device not simulator.注意:当您使用真实设备而不是模拟器运行时,此代码可以工作。 And don't forget add LSApplicationQueriesSchemes in your info.plist.并且不要忘记在 info.plist 中添加 LSApplicationQueriesSchemes。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 呼叫号码功能错误canOpenURL:URL失败:“ tel:// 0478733797”-错误:“此应用程序不允许查询方案tel” - Call number function error canOpenURL: failed for URL: “tel://0478733797” - error: “This app is not allowed to query for scheme tel” 沉默“-canOpenURL:URL失败:” - Silence “-canOpenURL: failed for URL:” -canOpenURL:URL失败:“ fbauth2:/”-iOS 9错误:“(空)”(快速) - -canOpenURL: failed for URL: “fbauth2:/” - error: “(null)” for ios 9 (swift) swift3-替换网址 - swift3 - replace url 将 Dropbox 连接到 swift 5 失败并出现错误 -canOpenURL: failed - connecting Dropbox to swift 5 fails with error -canOpenURL: failed -canOpenURL:URL失败:“ spotify:”-错误:“(null)” - -canOpenURL: failed for URL: “spotify:” - error: “(null)” -canOpenURL:URL失败:“fbauth2:/” - 错误:“(null)” - -canOpenURL: failed for URL: “fbauth2:/” - error: “(null)” iPod Touch canOpenURL类型为tel:// - iPod Touch canOpenURL of type tel:// 带有firebase canOpenURL的Swift Facebook Auth:URL失败:“ fbauth2:/”-错误:“该操作无法完成。 (OSStatus错误-10814。)” - Swift Facebook Auth with firebase canOpenURL: failed for URL: “fbauth2:/” - error: “The operation couldn’t be completed. (OSStatus error -10814.)” -canOpenURL:URL 失败:“fbauth2:/” - 错误:“操作无法完成。 (OSStatus 错误 -10814。)” SWIFT 5 FBDSKCoreKit 5 - -canOpenURL: failed for URL: “fbauth2:/” - error: “The operation couldn’t be completed. (OSStatus error -10814.)” SWIFT 5 FBDSKCoreKit 5
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM