1

Is there a way to open the phone app using swift? all the answer I see was to use UIApplication.shared.open(urlNumber) like this. but it's not opening the phone app, instead, it will create a pop up and a cancel or call option.

This is my expected output expected 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.

enter image description here

Android achieved it in here, how about the ios?

Jawad Ali
  • 13,556
  • 3
  • 32
  • 49
Dylan
  • 1,121
  • 1
  • 13
  • 28

2 Answers2

1

Its not possible to open direct phone app without dialogue. As Per Apple's documentation for 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.

Jawad Ali
  • 13,556
  • 3
  • 32
  • 49
  • For my expected result, it's okay to have a dialog before opening the phone app, as long as it opens the phone app, my current example code was a dialog but it didn't open the app, instead if you press call, it will automatically call that number. – Dylan Jun 25 '20 at 08:01
  • 1
    its default behaviour ... there is no other API available to call – Jawad Ali Jun 25 '20 at 08:03
  • so it's not possible to open the phone app using swift? – Dylan Jun 25 '20 at 08:11
  • I'm sorry but the link you provided doesn't say anything why I can't open the phone app, the answer was just saying that It's not possible to open the phone app and I still don't know why – Dylan Jun 25 '20 at 13:27
  • so it did not helped you ? found anything that can work? or my answer is good enough ? :) – Jawad Ali Jun 25 '20 at 17:22
  • The answer was in your comment saying `its default behaviour ... there is no other API available to call`, I'm just get little bit confused but that does mean that there is no such a feature apple created. I pretty enlightened by the comments at this answer https://stackoverflow.com/a/62580270/6800631 saying that `It can't be done by anyone unless Apple allows it` – Dylan Jun 25 '20 at 17:44
1

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)
}