When you click the notification in the notification bar to enter the program, the method in App Delegate will be triggered, which is divided into the following two situations:
1. When the program is not started (that is, there is no process in the bottom taskbar):
In this case, clicking the notification in the notification bar to enter the program will trigger the following method
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
For launchOptions parameter, the following processing is required:
NSDictionary* pushNotificationKey = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
The pushNotificationKey is the data pushed from the server. You can use the key-value pair to read the extra parameters passed by the server.
The application has not loaded yet. If you click the display button of the notification, you will call didFinishLaunchingWithOptions, and will not call the didReceiveRemoteNotification method. If you click the notification close button and then click Apply, only the didFinishLaunchingWithOptions method will be called.
2. The program has been started:
If the program has been started and resides in memory, regardless of whether the program is in the foreground or in the background, if you click the notification bar to enter the program, the following method will be triggered:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
The userInfo parameter is already the data pushed by the server and is also read using key-value pairing.
If you click Close and then click on the application, neither of the above methods will be called. You can only use the applicationWillEnterForeground or applicationDidBecomeActive to determine whether there is a notification based on the badge in the sent notification, and then send a request to obtain the data
The above is all the content of this article. I hope that the content of this article will help you study or work. I also hope to support me more!