1

I have an iOS application that programmatically lets the user make a phone call.

I would like to display a popup asking a question when the user's phone call has finished (and the user is automatically taken back to the app they made the phone call from).

What is a recommended way to do this in swift?


Here is the current code:

    @IBAction func makePhoneCall(_ sender: UIButton) {
        let phone = getPhone().filter(characterOkay)
        if let url = URL(string: "tel://\(phone)"), UIApplication.shared.canOpenURL(url) {
            if #available(iOS 10, *) {
                UIApplication.shared.open(url)
            } else {
                UIApplication.shared.openURL(url)
            }
        }

        // This incorrectly shows the popup before the phone call. 
        showQuestionPrompt();
    }
Eric Aya
  • 69,473
  • 35
  • 181
  • 253
aero
  • 1,654
  • 1
  • 21
  • 31
  • 1
    I think you can have a look at this it might give you some reference [Link](https://stackoverflow.com/questions/18310332/detecting-the-call-events-in-ios) just keep in mind that apple are a little picky about why you are putting the code in background and listening. they might reject the app if you do not have proper definition why you need it. hope it works :) – saj Feb 14 '18 at 20:27
  • 1
    Upvoted the comment. Basically, you want your app to be a delegate - if possible - of the phone call. I don't know if that is possible, but if so, then you have your "hook" into when the call is finished or closed. BT, could you show us the *code* that lets the user make a phone call? It would help us greatly to help you. –  Feb 14 '18 at 20:36
  • @dfd Thanks, dfd. I updated my question with the current code. I'll look into if "hooking" into the phone call is possible. That's an interesting possibility. – aero Feb 14 '18 at 20:44
  • 1
    @sajidgangat Thanks for the link Sajid, I will look into it's possibility. – aero Feb 14 '18 at 20:45

0 Answers0