0

I'm developing an app using Ionic 2. This app must receive push notifications.

In some situations the app will be killed like the "Force Stop" option in Android. I other situations the device will be shutdown. In such situations my app don't will receive push notifications, even if background-mode plugin is enabled.

Anyway I know that push notifications are stored in some place, in a queue waiting to be delivered. When I start again my app, the notifications sent while my app was not running are not automatically received by the app. If I receive a new notification at this moment all notification sent when my app was stopped will be received by my app.

My question is how could I force my app to receive notifications sent when the app was stopped or ask to GCM to send this notifications?

Natanael
  • 1,326
  • 5
  • 17
  • 34
  • Although this [SO question](http://stackoverflow.com/questions/12073449/android-gcm-push-notification-device-doesnt-receive-notification-if-applicat?rq=1) is in android, I think it can give you an idea how GCM works while the app is stoped. – KENdi Jul 26 '16 at 10:18
  • Thanks for reply. This topic doesn't address the exactly same question. They talk about how the on receiver listener is not called **WHILE** the app is forced closed. My doubt is about how to receive the messages sent **WHILE** the app is force closed **AFTER** it is reopened. I know this is possible because I made a test. But to receive the notification sent while the app was force closed GCM needs to send a new notification. This behaviour was seen even for messages sent when the device was turned off. – Natanael Jul 26 '16 at 12:13

2 Answers2

0

When using GCM if your app is stopped (not just in the background) your application cannot receive GCM messages. Those messages will be lost.

If your device is not connected eg: off, then the messages can be saved by GCM (see time_to_live field) and then when the device comes back online the message will be sent, if the app had not been previously stopped then it will receive the message.

Arthur Thompson
  • 9,087
  • 4
  • 29
  • 33
  • Thanks for reply, but it's not exactly the answer. You get very near. It looks time_to_live is 4 weeks by default. The property need here is delay_while_idle as true. Correct me if I'm wrong. – Natanael Jul 26 '16 at 18:56
0

Solved!

The problem was a GCM configuration backend in the backend not in my app front end.

According to this documentation "delay_while_idle" must be set as true.

Changing this property makes the messages to be delivered even if the device is turned off or the app is killed. The mensagens are sent once the device is turned or and the app open.

Natanael
  • 1,326
  • 5
  • 17
  • 34