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

谁说胖子不能爱 提交于 2019-12-07 11:38:02

问题


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?


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/45980857/prompt-when-trying-to-dial-a-phone-number-using-tel-scheme-on-ios-11

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!