Here is something I grabbed from a previous project.
You can setup a notification observer to check if the app has "moved to background", so basically when the user exits the app.
init() {
let notificationCenter = NotificationCenter.default
notificationCenter.addObserver(self, selector: #selector(appMovedToBackground), name: UIApplication.willResignActiveNotification, object: nil)
}
Just throw that in your main viewcontroller's init method and...
@objc func appMovedToBackground() {
print("App moved to background")
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…