Open Gionni opened 9 years ago
This is what I understand. But it doesn't fit into my case. In my opinion it SHOULD also fire in background and even if app isn't started yet. Is there any workaround for it? I need to sync local data on push and use it not only to inform the user with a notification in the bar.
If you're in normal circumstances, you can just ajax-sync your data on the resume event. This suits you.
The problem is if inside your app you make other system stuff (e.g. calls/sms/email) because in that case you got a lot of resume events and it seems to me you can't distinguish them from the initial.
but if it doesn't fire the ecb function when app is in background, I couldnt do anything, no?
or maybe I dont understand what you mean. do you have a quick example? thanks
No, as far as I know nothing. But maybe you don't need it.
On my ecbs (onNotificationGCM, onNotificationAPN) I put sync logic, why don't do the same with onResume: function() { ... } fired by "document.addEventListener('resume', this.onResume, false)"?
This way app in background stay not updated but when user open/resumes it'll be sync on-fly. Is not enough for your circumstances?
Maybe I have to go that way :/
My app is based on database entries which are generated by other users. when they post a new entry, the server sends a push to all users based on their location. the pushed data has geofence informations. when a users receives a push fron server, the app should add a new geofence to the geofence plugin. then when the user enters a geofence, other functions start. so the gcm pushes should fill the local storage. the rest of the magic should work in background.
maybe I have a wrong thinking to solve that problem.
any suggestions? thank you :)
So I want to keep the local storage up to date, also with silent pushing. Posts (geofences) have a very short lifetime (2 hours). I cant notify the user all the time, because that would be annoying and they would delete the app instantly.
Hi, I have the same requirements as bwasnie1, I think we need something like: 1) add a local storage to the PushPlugin to store all received notifications, specialy when the main application is in background, 2) allows main the application to retreive sotred notifications on resume
What do you think ?
Best regards
Yes, that would be perfect! But I am not experienced in Java, thats why I use cordova ^^
I didn't understand the exact needs of bwasnie1 (sorry, too much work, headache) but sam74 is right: just writing a local storage would solve all. Maybe it's not necessary create a lot of logic, maybe just a flag would be enough. So you'd know there was a notification and you could retrieve it with your logic at the really-first resume event. What do you think? I'm not good in java as well but I need it and I could fork it and try to merge.
Hi, i have created a fork for the project, I will try to give some solution for the issue. cheers,
It seems easy in Android. But we gotta do the same for iOS... For now these 2 platforms can be enough.
i can do something in android, but i have no exprience in iOS.
Same here. I got no imac, that's why I use PGB :(
the idea is to add some buffer to 1) store messages when foreground is false 2) send bufferd messages to webview onresume
I gotta improve my code but following my minimal request about a flag for knowing if there were notifications in background if I resume my app without tapping the notification bar (because unfortunately my customers often don't do that), this works for my needs:
I add: PushNotification.prototype.resume = function(successCallback, errorCallback, options) { cordova.exec(successCallback, errorCallback, "PushPlugin", "resume", [options]); }; I call it at every resume (including lots of false positives) in my index.js, sync in first callback: pushNotification.resume(app.trueFlagBackgroundNotificationResumeHandler, app.falseFlagBackgroundNotificationResumeHandler, {});
I add this in "onMessage" in else of "if (PushPlugin.isInForeground())": PushPlugin.setFlagBackgroundNotification(true);
I add: public static final String RESUME = "resume"; private static boolean gFlagBackgroundNotification = false;
} else if (RESUME.equals(action)) { Log.v(TAG, "RESUME"); if (gFlagBackgroundNotification) callbackContext.success(); else callbackContext.error("silence");
public static void setFlagBackgroundNotification(Boolean val) { gFlagBackgroundNotification = val; }
D'you think it could be a solution?
I guess you two have maybe more needs, but if you put too much logic into the package, I'm not sure the contributors are willing to merge it. If you think the minimal approach could be ok, I'll investigate the same for iOS. Maybe not very soon, I got priorities.
The problem was explained here: https://github.com/phonegap-build/PushPlugin/issues/68 They're talking about iOS (in Android however I got the same problem, that's why I patched it my way) and they say 2.4.0 totally solved the problem. But it doesn't work in my ipad yet. Could it be depending upon iOS version (old)?
Anyway, I don't understand why this August Mechanicalee writes "The push notification is only accessible when clicking the notification and not when clicking the app icon. This is not actually an issue and is just how iOS works." and in October bau720123 and marek1 say 2.4.0 solved all. If it's standard behavior, what is to fix?
@Gionni I am wondering your point 2.2 the onResume by clicking the icon when App is in the background, if that point is fixed. You mentioned in the last comment, that it is fixed and is standard behavior on 2.4.0. Because i am using version 2.4.0 with phonegap 3.7. And when onResume, my App just deletes the push notification from the tray but no ECB. So those messages just disappears.
I fixed this issue here #314 I have explained in detailed
Using Cordova 3.6.0 (local x Android) and 3.6.3 (PGB x iOS).
2.1 If App is in background (or never started), notification bar is updated and if I click on it, App will be opened and onNotificationGCM/onNotificationAPN will be fired. - OK -
2.2. If App is in background, notification bar is updated and I don't click on it and resume App anyway, onNotificationGCM/onNotificationAPN are not fired. - Is it correct? -
I'm asking it because I need to sync anyway in that case and I don't know if PushPlugin is doing right or wrong. If it's doing right, is there any way to know if there were notifications?
Thanks so much, Johnny