如何在applicationDidBecomeActive中确定它是否是最初的iPhone应用程序启动?

问题描述:

如何确定如何在UIApplicationDidBecomeActiveNotification中确定它是否是初始应用程序启动?是否是初始应用程序启动?

how to determine in how to determine in UIApplicationDidBecomeActiveNotification whether it is the initial app launch?whether it is the initial app launch?

这是初始启动时间应用程序,而不是后续的DidBecomeActive,因为应用程序被放在后台然后到前台(例如用户转到日历然后回到你的应用程序)

that is the initial start up of the application, as opposed to subsequent DidBecomeActive's due to the application being put in background and then to foreground (e.g. user goes to calendar then back to your app)

在你的 applicationDidFinishLaunching:withOptions:把这个:

[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"alreadyLaunched"];
[[NSUserDefaults standardUserDefaults] synchronize];

然后,在 didBecomeActive

if ([[NSUserDefaults standardUserDefaults] boolForKey:@"alreadyLaunched"]) {
    // is NOT initial launch...
} else {
    // is initial launch...
}