首页 > 解决方案 > didReceiveNotificationResponse method is not called when the app gets launched through notification swipe from a closed state

问题描述

I have observed that didReceiveNotificationResponse method is called when I re-launch the app from the background through a push notification swipe. But it is not getting called when I closed the app and re-launched through a push notification swipe.

- (void)userNotificationCenter:(UNUserNotificationCenter *)center
   didReceiveNotificationResponse:(UNNotificationResponse *)response
    withCompletionHandler:(void (^)())completionHandler
    {
       // Sending analytics to my server
 }

I am verifying this through my analytics backend and I can see all the launches from the background through notification swipe are reflected but the other one is not. In both cases, I am hitting the same API, so ideally it should get updated.

The following is my didFinishLaunchingWithOptions method:

-(BOOL)application:(UIApplication*) application didFinishLaunchingWithOptions:(NSDictionary*) launchOptions
{
 dispatch_async(dispatch_get_main_queue(), ^(void){
    //Run UI Updates
    if (@available(iOS 10, *)) {
        UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
        center.delegate = self;
        [center requestAuthorizationWithOptions:(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError * _Nullable error) {
        if( !error ) {
            // required to get the app to do anything at all about push notifications
            dispatch_async(dispatch_get_main_queue(), ^{
                [[UIApplication sharedApplication] registerForRemoteNotifications];
            });
            NSLog( @"Push registration success." );
        } else {
            NSLog( @"Push registration FAILED" );
            NSLog( @"ERROR: %@ - %@", error.localizedFailureReason, error.localizedDescription );
            NSLog( @"SUGGESTIONS: %@ - %@", error.localizedRecoveryOptions, error.localizedRecoverySuggestion );
        }
        }];
    }
});

Adding my notification content I am getting from a third-party service provider (Salesforce):

{
    "_h" = "V6bdjs7jjkqv/POIIIII";
    "_m" = MjJhJkKkK;
    "_mt" = 1;
    "_r" = "9dsdsjkk-3344dd-4edd-ade33-jhdj999";
    "_sid" = SFMC;
    aps =     {
        alert =         {
            body = test;
            subtitle = "Push Test";
            title = "Push Test";
        };
        "mutable-content" = 1;
        sound = default;
    };
}

I have enabled Remote Notifications from Background Modes also.

enter image description here

标签: iosobjective-cpush-notificationapple-push-notificationssalesforce-marketing-cloud

解决方案


推荐阅读