Search code examples
ioscordovaphonegap-pluginsphonegap-cli

Scheduling a local notification in PhoneGap/Cordova doesn't work on iOS simulator


  • Installed newest Xcode (7.3.1)
  • Installed newest PhoneGap (6.2.7)
  • Created default PhoneGap app
  • Installed local notification plugin using phonegap plugin add de.appplant.cordova.plugin.local-notification
  • Added code to create notification (see below)
  • Ran using phonegap run iOS
  • No notification appears

Code in index.js:

document.addEventListener('deviceready', function () {
    try {
        cordova.plugins.notification.local.schedule({
            text: "This is the text.",
            at: new Date(new Date().getTime() + 10000)
        });
    } catch (e) {
        alert("Fail " + e);
    }
});

Any suggestion as to what I'm doing wrong?


Solution

  • I tried the same code and it runs on the simulator.

    I think you may be forgetting that notifications will not show if you are inside the app. Make sure you go back to the home screen once the app launches (using the shortcut cmd+shift+h), so that the app is in the background when the scheduled time comes (10 seconds) and the notification should show.

    You may want to keep the app in the foreground at the first run so that ios will prompt you to allow notifications. After that, restart the app and send it to background.