简体   繁体   中英

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

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://user@example.com")
            else { return }
        UIApplication.shared.open(faceTimeURL, options: [:], completionHandler: nil)
    }

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

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM