![](/img/trans.png)
[英]canOpenURL: failed for URL: "instagram://" - error: "This app is not allowed to query for scheme instagram"
[英]Call number function error canOpenURL: failed for URL: “tel://0478733797” - error: “This app is not allowed to query for scheme tel”
我在日志中收到此錯誤?
盡管我在模擬器上運行此程序,但在測試階段這有關系嗎?
canOpenURL:URL失敗:“ tel:// 0478733797”-錯誤:“不允許此應用程序查詢方案tel” callNumber按鈕
這是我的功能。
字符串是“ 0478733797”
func callNumber(phoneNumber:String) {
if let phoneCallURL = URL(string: "tel://\(phoneNumber)") {
let application:UIApplication = UIApplication.shared
if (application.canOpenURL(phoneCallURL)) {
application.open(phoneCallURL, options: [:], completionHandler: nil)
}
}
}
您面臨的錯誤說明您不允許您的應用打開查詢方案。 為了解決這個問題,您應該在info.plist中添加以下權限
<key>LSApplicationQueriesSchemes</key>
<array>
<string>tel</string>
</array>
並在設備而不是模擬器上運行您的應用程序
要撥打電話,您只需要執行以下操作:
let urlSchema = "tel:"
let numberToCall = "0478733797"
if let numberToCallURL = URL(string: "\(urlSchema)\(numberToCall)")
{
if UIApplication.shared.canOpenURL(numberToCallURL)
{
UIApplication.shared.openURL(numberToCallURL)
}
}
僅使用tel:
創建的URL
格式不正確。
無需向Info.plist
添加任何內容。 另外, iOS Simulator
不支持通話。 因此,請嘗試在實際設備上運行它。
讓我知道您是否仍然遇到任何問題。 快樂編碼..🙂
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.