-1

I don't need to call the phone number, I just need the dialer to open with the phone number already displayed. What UIApplication.shared should I open to achieve this?

My question was similar to this one, but I don't seems to find any alternative for ios.

Dylan
  • 1,121
  • 1
  • 13
  • 28

2 Answers2

2

Use this:

let phoneNumber = "+123123123"
let numberUrl = URL(string: "tel://\(phoneNumber)")!
if UIApplication.shared.canOpenURL(numberUrl) {
    UIApplication.shared.open(numberUrl)
}

Related links:

  1. https://developer.apple.com/library/archive/releasenotes/General/RN-iOSSDK-10.3/
  2. https://developer.apple.com/documentation/uikit/uiapplication/1648685-open
Frankenstein
  • 15,732
  • 4
  • 22
  • 47
  • It's not opening the dialer but instead show a dialog box and direct to call the number – Dylan Jun 25 '20 at 16:48
  • 1
    Yes, it's ios native behaviour and you can't change that. iOS ask for the users consent to know if he wishes to call the number. You should know ios and android work differently. – Frankenstein Jun 25 '20 at 16:49
  • Means I can't open the dialer in ios? if I'm right, can you give me the link to that explanation so I can explain it clearly in my client? because they want that function to appear in their app. – Dylan Jun 25 '20 at 16:54
  • 2
    Yes, It can't be done by anyone unless Apple allows it, which is unlikely. Added related links. – Frankenstein Jun 25 '20 at 16:59
0

You cannot open the dialer/keypad within the phone app in iOS. Alternatively, you can design your own keypad in a view controller, add tones for keys and collect the number. Once you have the number, use following to make call:

func call() {

    let app = UIApplication.shared

    guard let number = URL(string: "tel://" + "1234567890"), app.canOpenURL(number) else {
        return
    }
    app.openURL(number)
}
grow4gaurav
  • 3,145
  • 1
  • 11
  • 12
  • First: that app.openURL was already deprecated and changed to app.open, Second: It's not opening the dialer but instead show a dialog box and direct to call the number, which is not the answer I was looking for. – Dylan Jun 25 '20 at 16:47