1

Is it possible to receive notification data when app is terminated without notification being pressed?

I'm using

func application( _ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) {}

It works fine if the app is in foreground or background, but it has no effect if the app is terminated, so my question is it possible to handle notification data in a delegate if app is terminated and how?

Thanks.

Varun
  • 85
  • 1
  • 7
MahmutTariq
  • 217
  • 1
  • 4
  • 17
  • You probably are looking for background refresh. Head over to RayWenderlich's [Background Modes Tutorial: Getting Started](https://www.raywenderlich.com/143128/background-modes-tutorial-getting-started) and also worth reading: tutplus' [iOS 7 SDK: Working with Background Fetch](https://code.tutsplus.com/tutorials/ios-7-sdk-working-with-background-fetch--mobile-20520) – Adil Soomro Dec 21 '16 at 08:41
  • 1
    I think this will help you: http://stackoverflow.com/questions/35058870/handling-push-notifications-when-app-is-terminated – Twitter khuong291 Dec 21 '16 at 08:43

1 Answers1

3

There are only following way to get Notification Data :

  1. If your app is open and you receive notification.(It will come in didReceiveRemoteNotification)
  2. If your app is in background and you tap on the notification to open the app.
  3. If your app is close and you receive a notification on device and you tap on notification you can open the app.(It will come in didFinishLaunchingWithOptions)

App will not be able to handled it if you don't tap on the notification. You can only process the old notification data by having a web service to give you the unread or unprocessed notifications.

Sneha
  • 1,444
  • 15
  • 24
  • Yeah, understandable. Thank you. – MahmutTariq Dec 21 '16 at 08:49
  • You probably want to clarify what "open" and "closed" mean (running, foreground, active / running, foreground, not active / running, background / suspended, background / terminated). You can receive notifications in an app that is in the background (running or suspended) even without interaction with the notification, provided the notification has the correct flag. – jcaron Dec 21 '16 at 11:23