![](/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.