我需要能够区分应用程序didFinishLaunching和应用程序进入后台并加载回前台。我注意到如果我注册UIApplicationDidBecomeActiveNotification,它会在两个实例中被调用。我如何区分这两者?
答案 0 :(得分:4)
使用didFinishLaunchingWithOptions
vs applicationWillEnterForeground
来区分app是冷启动还是从后台返回。
我尝试在我的某个应用中收听UINotification,但通知传送的时间太晚,所以我直接倾听这些方法调用。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// only call when app is freshly launched
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
// Only called when app is returning from background
}
答案 1 :(得分:0)
我需要能够区分应用程序 didFinishLaunching
UIApplicationDidFinishLaunchingNotification
申请进入背景
UIApplicationDidEnterBackgroundNotification
被加载回前景
UIApplicationWillEnterForegroundNotification