Swift 4.2 中 UIApplicationWillResignActiveNotification 的使用
在 Swift 4.2 中,使用 UIApplication.willResignActiveNotification 通知来监听应用程序即将进入后台的事件。该通知取代了之前的 NSNotification.Name.UIApplicationWillResignActive 语法。
以下是如何在你的代码中使用它:
NotificationCenter.default.addObserver(self, selector: #selector(appWillResignActive), name: UIApplication.willResignActiveNotification, object: nil)
appWillResignActive 是你定义的处理应用程序即将进入后台的函数。
注意:
在 Swift 4.2 及更高版本中,强烈建议使用 UIApplication.willResignActiveNotification,而不是旧的 NSNotification.Name.UIApplicationWillResignActive 语法。
原文地址: https://www.cveoy.top/t/topic/oR1Q 著作权归作者所有。请勿转载和采集!