[英]Open phone app with auto populated number in Swift
Is there a way to open the phone app using swift?有没有办法使用 swift 打开手机应用程序? all the answer I see was to use UIApplication.shared.open(urlNumber)
like this .我看到的所有答案都是像这样使用UIApplication.shared.open(urlNumber)
。 but it's not opening the phone app, instead, it will create a pop up and a cancel
or call
option.但它不会打开电话应用程序,而是会创建一个弹出窗口和一个cancel
或call
选项。
This is my expected output这是我预期的 output
the code that I was using right now was我现在使用的代码是
guard let number = URL(string: "tel://" + "+639123123123") else { return }
UIApplication.shared.open(number, options: [:], completionHandler: nil)
but like I said, it didn't open the phone app and the output of that code was this, which is not what I expect.但就像我说的那样,它没有打开手机应用程序,并且该代码的 output 是这样的,这不是我所期望的。
Android achieved it in here , how about the ios? Android在这里实现了,ios怎么样?
Its not possible to open direct phone app without dialogue.没有对话就无法直接打开电话应用程序。 As Per Apple's documentation for openURL:根据Apple 的 openURL 文档:
openURL打开网址
When a third party application invokes openURL: on a tel://, facetime://, or facetime-audio:// URL, iOS displays a prompt and requires user confirmation before dialing.当第三方应用程序在 tel://、facetime:// 或 facetime-audio:// URL 上调用 openURL:时,iOS 会显示提示并要求用户在拨号前确认。
This worked perfectly for me, plus you don't have to add any additional action sheets or alerts.这对我来说非常有效,而且您不必添加任何额外的操作表或警报。 An action sheet automatically pops up.操作表会自动弹出。
@objc private func didTapCall() {
let numberString = self.phoneText.text!
guard let url = URL(string: "telprompt://\(numberString)") else { return }
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.