didReceiveNotificationResponse called before didFinishLaunchingWithOptions in iOS 10

Hi there,


I just have a problem about notification in iOS 10.2.1:


When the app is killed (not run in background mode), then when a notification comes, I tap into notification, app will open, but insteads of calling

(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions


the system call first this method:

(void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler


then, didFinishLaunchingWithOptions is called.


That's weird as the documentation says that didFinishLaunchingWithOptions will be called firstly with notification info placed in launchOptions parameter.


So, Did anyone experience this problem? Please help!


Thank you!

I had this problem too and came up with tow solutions in


- (void)userNotificationCenter:(UNUserNotificationCenter *)center  
didReceiveNotificationResponse:(UNNotificationResponse *)response  
withCompletionHandler:(void (^)(void))completionHandle { …


Variant a) Working but using a fixed delay:


    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ 
       // handle the UNNotificationResponse 
        completionHandler(); 
    });


Variant b) Working and doing the job as soon as the app is ready:


    NSBlockOperation *notificationResponseOperation = [NSBlockOperation blockOperationWithBlock:^{ 
       // handle the UNNotificationResponse 
        completionHandler(); 
    }]; 
   
    [[NSOperationQueue mainQueue] addOperation:notificationResponseOperation];


Hope you like it :-)

didReceiveNotificationResponse called before didFinishLaunchingWithOptions in iOS 10
 
 
Q