Prompt when trying to dial a phone number using tel:// scheme on iOS 11

1.6k views Asked by At

I am facing an issue, while trying to start a phone call from my iOS app using:

UIApplication open(_:options: completionHandler:)

iOS shows an confirmation popup/alert before starting the call with two button Call & Cancel and CompletionHandler called with a Bool parameter having true/false based on button action in iOS 10.

But now in iOS11 the problem is that the completionHandler is being called automatically before tapping on "Cancel" or "Call" button of confirmation popup, always having true value.

Is this a bug in iOS11 or is there something that I am doing wrong?

2

There are 2 answers

8
Suryakant Sharma On

completionHandler will get a call if your given URL gets open success or failure, this has nothing to do with Cancel & Call buttons on Alert

see what Apple docs has to say about it HERE

completionHandler

The block to execute with the results. Provide a value for this parameter if you want to be informed of the success or failure of opening the URL. This block is executed asynchronously on your app's main thread. The block has no return value and takes the following parameter:

success

A Boolean indicating whether the URL was opened successfully.

0
user3113870 On

There has been a behavior change in when the closure is called in iOS 11. I cant say if this behavior will be reverted or if this is a bug. But one of the ways you can identify when the user interacted with the popup is by adding a notification listener around UIApplicationDidBecomeActive in the completion closure of openURL(). To identify whether the call was clicked or not you will need to create another custom notification and listener on the CTCallCenter. That was the best way through which I was able to identify it, there might be better solutions though :D