Search code examples
iosobjective-cios10nsusernotificationcenter

How to get Application states in iOS 10 notification?


I am using

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

for getting the notification response in iOS 10, can anyone tell me how to get the Application states in it ?

Because in iOS 9 or before I used

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

In this method, we can get the application state by

application.applicationState

thanks for the help.


Solution

  • I did some search and I got these methods

     - (void)userNotificationCenter:(UNUserNotificationCenter *)center  
    willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler{  
    NSLog( @"for handling push in foreground" );  
    // Your code
    NSLog(@"%@", notification.request.content.userInfo); //for getting response payload data
    }  
    
    - (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response  withCompletionHandler:(void (^)())completionHandler   {  
    NSLog( @"for handling push in background" );  
    // Your code
    NSLog(@"%@", notification.request.content.userInfo); //for getting response payload data 
    }