0

I receive a push notification when the my app is closed or canceled. Is there a way to set an nsuserdefault when this happens? I know if a user taps the notification or opens the app from the notification you can check if the app was inactive or canceled but what if they don't open the app from the notification but rather just launch the app by clicking on the icon?

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

I know this method is called but it seems like I can not save to nsuserdefaults if the app is terminated or canceled.

2
  • remote from server @Avi Jun 28, 2016 at 4:28
  • At a minimum, you should be using content-available: 1 in your payloads and using the correct delegate method to handle them. Then you have to live with the fact that background wakeup is not reliable.
    – Avi
    Jun 28, 2016 at 4:41

1 Answer 1

0

If the app is closed or inactive and user opens the app through the icon , you will get the remote notification in "didFinishLaunchingWithOptions" method if any notification is available , there you can set you userdefault if you want . Here is the code to get the remote notification in "didFinishLaunchingWithOptions"

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


if (launchOptions) { //launchOptions is not nil
    NSDictionary *userInfo = [launchOptions valueForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
    NSDictionary *apsInfo = [userInfo objectForKey:@"aps"];

    if (apsInfo) { //apsInfo is not nil
        [self performSelector:@selector(postNotificationToPresentPushMessagesVC) 
                   withObject:nil
                   afterDelay:1];
    }
}
return YES;
}

For more help please visit this link @staticVoidMan have answered it very well .

Hope this Helps!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.