didReceiveRemoteNotification not being called when I tap on app icon after receiving a push notification while on background

Mario Frade picture Mario Frade · Feb 14, 2014 · Viewed 13.6k times · Source

When my app is on background and I receive a remote notification, two things can happen:

  1. I tap on the push notification banner, my apps comes to foreground and didReceiveRemoteNotification is called.

  2. I tap on my app icon from the springboard, my app comes to foreground and didReceiveRemoteNotification IS NOT called.

So, in the scenario 1, I can update my counter of unread messages inside the app in response to didReceiveRemoteNotification. In the scenario 2, I can't.

How can I solve this using Quickblox?

Answer

frankWhite picture frankWhite · Feb 18, 2014

As one possible variant:

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    NSDictionary *userInfo = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
    if (userInfo) {
       [self handleRemoteNotifications:userInfo];
    }

    // Override point for customization after application launch.
    return YES;
}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
   [self handleRemoteNotifications:userInfo];
} 

#pragma mark - Remote notifications handling

 -(void)handleRemoteNotifications:(NSDictionary *)userInfo {
   // do your stuff
}

@end