简体   繁体   中英

Local notification on cordova 3.5.0 aren't working?

I used to add the https://github.com/katzer/cordova-plugin-local-notifications plugin in order to get local notification on my apps, but since the version 3.5.0 the plugin is not loaded anymore by cordova...

The plugin seems correctly added, since I can see it in the : cordova plugin list result

In the JS code I got

if(window.plugin && window.plugin.notification){
            window.plugin.notification.local.add({ message: 'a msg' }); 
        }

but window. plugin is undefined.

Am I missing something or something changed with the version 3.5.0?

The plugin will be available once the "Device is Ready". Listen the device ready event and then call you alert function.

https://github.com/jonbarlo/cordova-plugin-local-notifications#using-the-plugin

document.addEventListener('deviceready', function () {
   // window.plugin.notification.local is now available
}, false);

There is a surprise here. Whenever you enable a plugin, you have to download the debugger again, and install on the virtual machine / device for it to recognize the plugin. The docs didn't say it. I've just discovered it today.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM