I have integrated push notifications for my app. To catch the notifications I used this delegate.
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
in my app delegate.
So when the app is running in background if notification came and when I click on it this delegate fire. If the app is not running even in the background, If clicked on ntification then it fires
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
Sofar it worked well. Then I wanted to catch notification in the background. So I found
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
this works for it.
So I just change my previous didReceive
method into this new didReceive
method. Now my problem is when app launch with push notification (if app doesnt run in background or forground and when click on the notification when comes) my app crashes. Even I cant debug and catch this situation.
What is the difference between these 2 delegates. Does my 2nd delegate fire when app launch with a notification? Please help me.
Normally when a notification came then this method executes(when app is active) - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
But if the app is closed or killed by the system then click on the notificatin first calls the "didFinishLaunchingWithOptions" method i thsi method we have to check wether app starts from notification or a fresh start the we can use this code to call the "didReceiveRemoteNotification" method again
UILocalNotification *notification = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if (notification) {
[self application:application didReceiveRemoteNotification:(NSDictionary*)notification];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With