Local notification in phonegap 3.3.0

前端 未结 2 826
醉梦人生
醉梦人生 2020-12-31 22:10

Thank you Dawson! The problem mentioned below has been solved in android. But sadly it does not work when I build the project in ios, could anyone help?

相关标签:
2条回答
  • 2020-12-31 23:04

    You wont be able to call that function until after the deviceReady event has fired.

    For testing I always take my plugin function and add it as a click action to the "device is ready" p tag.

    Example:

    <p class="event received">Device is Ready</p>
    

    change to:

    <p class="event received" onclick="window.plugin.notification.local.add({ message: 'Great app!' });">Device is Ready</p>
    

    I do this with the default cordova example app since I know that 'Device is ready' will not display until after the deviceReady event has fired. This is a good way to test if plugins are working before you do any real work on your project.

    0 讨论(0)
  • 2020-12-31 23:09

    Hi guys just in case this is another example...it has custom sound and other properties such as title, badge type is interesting how this plugin doc is not finished yet, creating local notifications for android working absolutely beautiful with latest cordova (3.4.x) just create a var and assign your package name (the one you use when created the phonegap/cordova project with the command line something like this for example:

         cordova create LocalNotification com.example.localnotification LocalNotification
    

    Should be used in the plugin with these values:

        var package_name = "com.example.localnotification";
                        window.plugin.notification.local.add({
                                      date        : Math.round(new Date().getTime()/1000 + 5),
                                      title       : "Android App Tes Local Notification", 
                                      message       : "This is a new local notification.",
                                      repeat        : "daily",
                                      sound       : 'android.resource://' + package_name + '/raw/beep',
                                      badge           : 0,
                                      id             : 666,
                                      foreground      : function(notificationId){
                                      console.log("Hello World! This alert was triggered by notification " + notificationId);
                                      },
                                      background  : function(notificationId){
                                      console.log("Hello World! This alert was triggered by notification " + notificationId);
                                      }           
                                      });
    

    Download local notificator plugin (working on Android ONLY)

    Download beep.mp3

    stack overflow original comment

    0 讨论(0)
提交回复
热议问题