0

When App receives local notifications, didReceiveRemoteNotification has some operations. It works fine when app is in foreground. Also when app receives notification in background and open app by clicking on the notification. But NOT working when we open the app, without clicking the notification.

How to solve this ?

  if let options = launchOptions, notification = options[UIApplicationLaunchOptionsRemoteNotificationKey] as? [NSObject : AnyObject] {
            self.application(application, didReceiveRemoteNotification: notification, fetchCompletionHandler: { (NewData) in

            })
        }
Rosemol J
  • 183
  • 4
  • 19

1 Answers1

0

As you stated in your question...

Notifications are not working when we open the app, without clicking the notification.

This is your problem here. If you open app on tapping notification it will and it should work. If you open app without tapping on notification. it means you are not interested in notification but only interested to open the app. so there will be nothing of your notification.

You can get notification dictionary only when you (user) open app on tapping notification alert/banner.

If you want to get notification before any action to save it for you. as you mentioned in your comment below. you can go through from this post.

Community
  • 1
  • 1
M Zubair Shamshad
  • 2,741
  • 3
  • 23
  • 45
  • I've saving this notification data in coredata – Rosemol J Aug 17 '16 at 11:48
  • It should be saved even if we open the app from the notification or from the app list. – Rosemol J Aug 17 '16 at 11:49
  • @qwerty I have update my answer. have a look at this now. It will solve your problem. – M Zubair Shamshad Aug 17 '16 at 12:09
  • @qwerty There is nothing to worry about the code. You have to it as per your requirement after receiving notification. All you need to update your `plist` and notification `payload` . Then you can retrieve your notification in `didReceiveRemoteNotification:fetchCompletionHandler` – M Zubair Shamshad Aug 18 '16 at 04:09
  • In didReceiveRemoteNotification I am saving this notification data. But when a notification came, app was opened (without clicking the notification) , the notification automatically cancelled and save action is not performing – Rosemol J Aug 18 '16 at 04:15