【发布时间】:2023-04-11 11:18:01
【问题描述】:
这是我拨打电话的代码
let phoneCall = phoneNumberTF.text
if let phoneCall = phoneCall {
let url = NSURL(string: "tel://\(phoneCall)")
UIApplication.sharedApplication().openURL(url!)
}else {
let alert = UIAlertController(title: "Error", message: "not correct phone", preferredStyle: .Alert)
let action = UIAlertAction(title: "Retry", style: .Default, handler: nil)
alert.addAction(action)
}
我在日志中收到此错误
ERROR: There is no registered handler for URL scheme tel
提示:我已经检查过这个问题,但解决方案对我不起作用 Calling a phone number in swift
【问题讨论】:
-
你是在真机上测试吗?您无法在模拟器中拨打电话。
-
顺便说一句 - 你应该检查
openURL的结果。 -
@rmaddy 哦,我真的连打电话的控制器都打不开?
-
错误消息来自对
openURL的调用。这在模拟器上会失败,因为模拟器上没有手机。 -
尝试将
tel://更改为telprompt://而且它只适用于实际手机。