[英]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下面的代码是用来打开一个face time并建立一个连接,但是一旦调用结束后如何进行某个操作,“completionHandler”只是用来知道连接是否建立
UIApplication.shared.open(url, options: [:],completionHandler:nil)
like喜欢
UIApplication.shared.isClosed() UIApplication.shared.isClosed()
The URL opened is facetime URL打开的URL是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.如果您是该应用程序的开发人员,则不可能知道第三方应用程序的 state(在您的情况下为 facetime),您可能可以创建一个应用程序组来存储有关应用程序 state 的一些信息,据我所知知道,FaceTime 没有公共 API。
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:您可以使用 AppDelegate 的方法:
applicationWillEnterForeground(_:)
documented here applicationWillEnterForeground(_:)
记录在这里applicationDidBecomeActive(_:)
documented here applicationDidBecomeActive(_:)
记录在这里or you can observe those notifications或者你可以观察那些通知
willEnterForegroundNotification
documented here willEnterForegroundNotification
记录在这里didBecomeActiveNotification
documented here didBecomeActiveNotification
记录在这里Here's an example of how your view controller would look like这是您的视图 controller 的示例
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
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.