I am currently creating an Android application using ionic / ngcordova. I am going to implement push notifications. I implemented push notifications as a service that is introduced at the app.run(function(){..}) stage. The registration part works, and I get a callback containing regid . In addition, when the application is in an active state, an event is raised and a notification is received.
The problem I am facing is that when the application goes into the background, notifications are not accepted at all. I would expect a local notification to be raised when the application is not running or something like that, but absolutely nothing happens, which is strange.
I tried the Internet over the past few days, looking for a solution, but I could not find anything that tells me that it should just work.
Below is my application notificationService.js inside my application
app.factory('notificationService', ['$cordovaPush', function($cordovaPush){ var dataFactory = {}; // // When the device is ready and this service has been plumbed in... document.addEventListener("deviceready", function(){ console.log("initializing push notifications..."); _register(); }, false); // // Registers the device for push notifications... var _register = function(){ var config = {}; if ( device.platform == 'android' || device.platform == 'Android' || device.platform == "amazon-fireos" ){ // TODO: centralise this value as it can change... config = { senderID: "448168747432", ecb: "onNotificationGCM" }; }else { // iOS config = { "badge":"true", "sound":"true", "alert":"true" }; // Can add the following property to the config object to raise a callback with the information if need be... // "ecb": "onNotificationRegisterAPN" } $cordovaPush.register(config).then(function(result){ // // Typically returns "ok" for android and devicetoken for iOS console.log(result); }); }; window.onNotificationGCM = function(result){ console.log(result); /* I get called when the app is in the foreground, but nothing happens when the app is in the background. */ }; dataFactory.register = _register; return dataFactory; }]);
If this helps, I use PushSharp through the .net app to deliver notifications. Any help would be greatly appreciated.
UPDATE: I use the following / libs frameworks:
- Ionic Framework 1.2.14-beta6
- Cordoba 4.2.0
- Pushplugin
source share