[英]Call number function error canOpenURL: failed for URL: “tel://0478733797” - error: “This app is not allowed to query for scheme tel”
I am getting this error in the log? 我在日志中收到此错误?
Though I am running this on the simulator, will this matter in the testing stage? 尽管我在模拟器上运行此程序,但在测试阶段这有关系吗?
canOpenURL: failed for URL: "tel://0478733797" - error: "This app is not allowed to query for scheme tel" callNumber button pressed
canOpenURL:URL失败:“ tel:// 0478733797”-错误:“不允许此应用程序查询方案tel” callNumber按钮
Here is my function. 这是我的功能。
The string is "0478733797" 字符串是“ 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)
}
}
}
The error you are facing describes that you have not allowed your app to open an query scheme. 您面临的错误说明您不允许您的应用打开查询方案。 To solve that you should add following permission in your info.plist
为了解决这个问题,您应该在info.plist中添加以下权限
<key>LSApplicationQueriesSchemes</key>
<array>
<string>tel</string>
</array>
And run your application on the Device instead of Simulator 并在设备而不是模拟器上运行您的应用程序
To make a call to a number, you simply need to do this: 要拨打电话,您只需要执行以下操作:
let urlSchema = "tel:"
let numberToCall = "0478733797"
if let numberToCallURL = URL(string: "\(urlSchema)\(numberToCall)")
{
if UIApplication.shared.canOpenURL(numberToCallURL)
{
UIApplication.shared.openURL(numberToCallURL)
}
}
Only the URL
that you are creating using tel:
is not in the correct format. 仅使用
tel:
创建的URL
格式不正确。
There is no need to add anything to the Info.plist
. 无需向
Info.plist
添加任何内容。 Also, call is not supported on an iOS Simulator
. 另外,
iOS Simulator
不支持通话。 So try running it on an actual device. 因此,请尝试在实际设备上运行它。
Let me know if you still face any issues. 让我知道您是否仍然遇到任何问题。 Happy Coding..🙂
快乐编码..🙂
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.