我的Swift里有这样的代码:
Text(item.telephone)
.onTapGesture {
guard let number = URL(string: "tel://" + item.telephone) else { return }
UIApplication.shared.open(number)
}我想让它把它的号码叫做它的表演。我尝试了+994和+994,但在这两种情况下,我都得到了
Failed to open URL tel://0501234556: Error Domain=NSOSStatusErrorDomain Code=-10814 "(null)" UserInfo={_LSLine=247, _LSFunction=-[_LSDOpenClient openURL:options:completionHandler:]}我该如何解决这个问题?
发布于 2020-06-22 00:07:14
更新:您似乎正在使用模拟器打开tel://,这将产生您得到的错误。因此,在执行open()之前,请检查是否可以使用canOpen()打开url。
Text(item.telephone)
.onTapGesture {
guard let number = URL(string: "tel://" + item.telephone) else { return }
if UIApplication.shared.canOpenURL(number) {
UIApplication.shared.open(number)
} else {
print("Can't open url on this device")
}
}注意:确保参数的item.telephone不包含除数字以外的任何内容。
https://stackoverflow.com/questions/62500655
复制相似问题