Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why didReceiveRemoteNotification:fetchCompletionHandler is called but usual didReceiveRemoteNotification isn't?

In my application I have two types of push notifications: remote silent notifications with content-available = 1 flag and usual push notifications with body, badge and other stuff.

I also define two delegate methods didReceiveRemoteNotification:fetchCompletionHandler and usual didReceiveRemoteNotification.

But when a push-notification without content-available flag arrives didReceiveRemoteNotification:fetchCompletionHandler is called, instead of didReceiveRemoteNotification.

How to fix this?
Why can't I have two delegate methods for background and usual pushes?

like image 240
MainstreamDeveloper00 Avatar asked Feb 18 '14 12:02

MainstreamDeveloper00


1 Answers

iOS 7 only calls the new one, this is how I handled it in my app:

-(void) application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {

    // Pass on
    [self application:application didReceiveRemoteNotification:userInfo fetchCompletionHandler:nil];

}

-(void) application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {

    // Check if in background
    if ([UIApplication sharedApplication].applicationState == UIApplicationStateInactive) {

        // User opened the push notification

    } else {

        // User hasn't opened it, this was a silent update

    }

}
like image 100
jjv360 Avatar answered Oct 03 '22 16:10

jjv360