katzer / cordova-plugin-local-notifications

Cordova Local-Notification Plugin
Apache License 2.0
2.56k stars 1.75k forks source link

Callbacks are not getting called #119

Closed knusperpixel closed 10 years ago

knusperpixel commented 10 years ago

Phonegap 3.3.0 LocalNotification 0.7.2 iOS 7.1

I have added the plugin via PGB <gap:plugin name="de.appplant.cordova.plugin.local-notification" version="0.7.2" />

I keep the app running in background by setting this preference in config.xml: <preference name="exit-on-suspend" value="false" />

I have registered callbacks for add, click and trigger:

window.plugin.notification.local.onadd = function(id, state, json) {
  console.log('Notification added '+id+' State '+state+' data '+json);
  $('#debug').html('Notification added '+id+'<br />State '+state+' data'+json);
};
window.plugin.notification.local.ontrigger = function(id, state, json) {
  console.log('Notification triggered '+id+' State '+state+' data '+json);
  $('#debug').html('Notification triggered '+id+'<br />State '+state+' data'+json);
};
window.plugin.notification.local.onclick = function(id, state, json) {
  console.log('Notification clicked '+id+' State '+state+' data '+json);
  $('#debug').html('Notification clicked '+id+'<br />State '+state+' data'+json);
};

where $('#debug') is just a div.

I add a local notification with this code (after deviceready):

window.plugin.notification.local.add({
  id: '1',
  date: new Date(Date.now() + 60*1000),
  message: 'Hello World',
  title: 'Local Notification',
  autoCancel: false,
  json: {
    type: 'Some type',
    foo: 'bar'
  }
});

The notification is displayed (if the app is not in foreground) but none of my callbacks get triggered. Is there something missing or is this a bug?

knusperpixel commented 10 years ago

I'm sorry, my bad. Forgot to JSON.stringify the json payload :-(

katzer commented 10 years ago

;)

dbrouard commented 9 years ago

Hi, I'm afraid I have a similar problem, and it's not due to a stringify.

This is how I add the notifications ( which sounds in the system ): window.plugin.notification.local.add({ date: new Date( alarm_time ), message: dateFormat( start,"HH.MM" )+": "+summary, badge: 1 });

And this is the onadd:

            if ( window.plugin!=undefined && window.plugin.notification!=undefined && window.plugin.notification.local!=undefined ){
                    alert("foo");
                    window.plugin.notification.local.onadd = function(id, state, json) {
                            alert("bar");
                    };
            }

I get the "foo", but not the "bar".

Any clue?