Skip to content
This repository has been archived by the owner on Sep 4, 2020. It is now read-only.

Can I access Web API's from 'notification' handler? #335

Closed
avielfedida opened this issue Nov 14, 2015 · 7 comments
Closed

Can I access Web API's from 'notification' handler? #335

avielfedida opened this issue Nov 14, 2015 · 7 comments
Labels

Comments

@avielfedida
Copy link

Hello everyone, I just started using this great plugin, on the notification handler I check to see if it's a foreground notification and if so I alert the notification data, if not I use IndexDB+shim to save the data, when the application starts it looks like the data was never saved by IndexDB, I had the same problem with using localStorage so I'm doing something wrong, should I listen to specific event inside the notification handler and only then use a web API?

To make myself clear, I alert() the saved(supposedly) data immediately after the deviceready event(I assume that at the moment the notification is received the notification handler is called and my data is saved), I've learned somewhere that only when the notification is clicked only then the handler is called but I'm pretty confused, I assume that there is a problem to access Web API's when background notification is received, I don't know if I should use a IndexDB plugin or I should alert the saved data after another event then deviceready, have a nice day.

@fredgalvao
Copy link
Collaborator

Background notifications will not trigger a full reload of the application, so you won't have a new deviceready event everytime. I don't know exactly how your code is setup, but that might help investigate a bit further.

@avielfedida
Copy link
Author

@fredgalvao Thanks for the response I didn't know that, when you say not a full reload..., do I have access to Web API's or plugins?, can I silently launch my app if I can't?, basically what I try to understand is how can I save data received from background notification, I tried to use localStorage/IndexDB/IndexDB plugin, all of them fail to save the data, I'm sure there is a standard(or at least correct) way to do so, I'm new to cordova but I'd be glad if you know a way to save those background notification data.

@avielfedida
Copy link
Author

@macdonst I retested, and I can say for 100% that the callback is not called at all when the app is at the background, I click the notification, the deviceready event fires, but there is no call at all to the notification handler, I'm using Parse to send push notifications(my android version is 4.4.4), the properties object that sends the notification via parse contains content-available, message, alert, title and extra route property, when I run PN while the app is at the foreground the data is received, when I drop the app at the background(and I debug that) the notification handler is not being called, I saw developers having problems with localStorage + IndexDB, btw I tried both(tested IndexDB), using timers to fix those kind of problems, but I have no idea where should I use timers or why, @fredgalvao I'd be glad if you could explain what do you mean by "not trigger a full reload", I'm sure someone needs to save background PN data, if anyone knows a working example(small app) that uses background PN data and do it the "right way" it could really help.

@fredgalvao
Copy link
Collaborator

So, let me try to clarify. ( @macdonst explained all the scenarios pretty well in here)

When you say "background notifications", I expect you refer to the following scenario:

  • [1] App is opened by the user
  • User switches to another app using the multi-task button on android or presses the home button on android
  • App is now on background status, which means it's technically still running, on a paused state

At that point when you receive a notification with either a title or a message, it will:

  • Show a Notification on the "shader"/"notification center"

And if you click it, the plugin will:

  • Bring your app to foreground status
  • Trigger your notification event handler

In no point in any of these steps, did your app get the need to reload, or reopen, because it was already so. deviceready should never trigger, for the device was ready a long time ago (since when the user first opened the app at step [1]).

Now,

when you say that when you click on the notification, your app opens and the deviceready event triggers, I can pretty much assure you that this is not a background notification per se, but a cold start notification (these terms are not canonic btw 😉).

In that case, this plugin doesn't support cold start notifications on android yet, but it's pretty much on the way to being implemented afaik.

@avielfedida
Copy link
Author

@fredgalvao You are perfectly right, thank you so much for that clarification, I knew about pause event but most times I click the back button and the app is always on the "just used" apps list so ;), anyway I will be looking forward for that cold start, it can really help, thanks again and have a nice day.

@fredgalvao
Copy link
Collaborator

You're welcome!

@lock
Copy link

lock bot commented Jun 5, 2018

This thread has been automatically locked.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 5, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests

3 participants