【发布时间】:2018-01-30 10:08:59
【问题描述】:
我试图弄清楚 AppDelegate 方法是如何工作的。
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
print("didFinishLaunchingWithOptions")
return true
}
func applicationWillResignActive(_ application: UIApplication) {
print("willResignActive")
}
func applicationDidEnterBackground(_ application: UIApplication) {
print("didEnterBackground")
}
func applicationWillEnterForeground(_ application: UIApplication) {
print("willEnterForeground")
}
func applicationDidBecomeActive(_ application: UIApplication) {
print("didbecomeActive")
}
func applicationWillTerminate(_ application: UIApplication) {
print("willTerminate")
}
}
第一次启动应用程序时,它似乎按预期工作。 但是一旦强行终止应用程序,之后这些方法就不会被调用了。
有没有办法在强制终止应用后调用这些方法?
- xcode 9.2
- swift4
- 模拟器上的ios11.2
【问题讨论】:
-
关闭应用程序时连接终止。这样就不会调用 app-delegate 中的方法。
标签: ios swift appdelegate