Ramu
Ramu

Reputation: 11

UIApplication.shared.open , swift completion of a connection handling

The below code is used to open a face time and establish a connection, but how to do a certain operation once the call is ended, the "completionHandler" is used only to know if the connection is establised or not

UIApplication.shared.open(url, options: [:],completionHandler:nil)

like

UIApplication.shared.isClosed()

The URL opened is facetime URL

Upvotes: 0

Views: 1992

Answers (1)

Mario
Mario

Reputation: 459

It is not possible to know the state of a third-party app (facetime in your case) if you're the developer of that app you could probably create an app group to store some info about the app state and, as far as I know, FaceTime doesn't have public APIs.

A workaround in your case would be to observe when your app is in foreground again and do your stuff.

You can use AppDelegate's methods:

or you can observe those notifications

Here's an example of how your view controller would look like

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        NotificationCenter.default.addObserver(self, selector: #selector(appDidBecomeActive),
                                               name: UIApplication.didBecomeActiveNotification,
                                               object: nil)
    }

    private func openFaceTime() {
        guard
            let faceTimeURL = URL(string: "facetime://[email protected]")
            else { return }
        UIApplication.shared.open(faceTimeURL, options: [:], completionHandler: nil)
    }

    @objc private func appDidBecomeActive() {
        // do your stuff
    }

}

Upvotes: 0

Related Questions