简体   繁体   中英

Objective-c queue of calling appdelegate methods

In UIApplicationDelegate we have such methods like:

- (void)applicationWillEnterForeground:(UIApplication *)application

and

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification

Almost everytime applicationWillEnterForeground is calling first, but I detect that sometimes didReceiveLocalNotification is calling first, but it very seldom. I tried to find some explanation about this , but without any result. In https://developer.apple.com/library/ios/documentation/iphone/conceptual/iphoneosprogrammingguide/iphoneappprogrammingguide.pdf I didn't find this information

This phenomenon I met in iOS 8 beta and iOS 7.1 in different devices. Maybe anybody knows why or maybe has link on documentation where described this strange phenomenon of calling appdelegate methods

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification

Will be called each time you receive a local notification AND the app is opened (either in background or foreground), while

- (void)applicationWillEnterForeground:(UIApplication *)application

will be called only when the app is about to become the foreground app. The two methods are not directly related since if your app is opened and in foreground the applicationWillEnterForeground has already been called and the didReceiveLocalNotification will be called each time a new notification is received, if the app is opened but in background only didReceiveLocalNotification will be called UNLESS the user open the app after receiving it (thus the applicationWillEnterForeground will be called too). If the app is NOT opened at all and the app receive a push notification no method will be called BUT if the user open the app by interacting with the notification the

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

will be called with the key UIApplicationLaunchOptionsRemoteNotificationKey set in the launchOptions dictionary.

In general you should not expect one to be called before the other since the two methods are not strictly related, maybe what you want to achieve is possible through other way. If that's the case you should expand your answer with your goals in order to get suggestions on how to do it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM