4
  • 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?

Zarkonnen
  • 22,200
  • 14
  • 65
  • 81
  • No Mac available for me to test, but I presume you've verified that the event fires and the handler is called, e.g. by console logging or calling `alert` at the top of the function? That would narrow it down to the `cordova` call at least, may lead to a bug report? ---[Also @sage444 that's ticks, not seconds - it's scheduled only 10 seconds away, not 2.7 hours.] – brichins Jun 16 '16 at 22:35
  • @brichins thanks for clarification – sage444 Jun 17 '16 at 07:59
  • @Zarkonnen Tried testing the same in Android and iOS device. It works fine in Android and but could not get it work on iOS device (Strangely no error trace too). But when i tested in simulator, this is the error i got in system log - "UILocalNotification: could not calculate next fire date - previous = 2016-06-17 09:44:23 +0000 : next = 2016-06-17 09:44:23 +0000 : repeatInterval = 2" – Gandhi Jun 17 '16 at 15:22
  • @Zarkonnen Above error seems to be a recurring issue in local notification plugin. Check out this links - https://github.com/katzer/cordova-plugin-local-notifications/issues/901 https://github.com/katzer/cordova-plugin-local-notifications/issues/234 Keep me posted. – Gandhi Jun 17 '16 at 15:24

2 Answers2

3

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.

gafi
  • 12,113
  • 2
  • 30
  • 32
  • Yep, that was actually it. The notifications were appearing, but not visible in any way. Thanks! – Zarkonnen Jun 19 '16 at 17:24
  • @Gaafar Hi, i couldnt get it work in iOS (both simulator & device) but works fine in Android. Got the error as mentioned in my previous comment for the question. Any clues? – Gandhi Jun 20 '16 at 05:23
  • @Gandhi can you share your code? Are you passing the correct date for the `at` property? Also try without the repeat interval – gafi Jun 20 '16 at 06:38
  • @Gaafar Thanks for the response. I tried the same code posted in the question: $(document).ready(function() { document.addEventListener("deviceready", onDeviceReady, false); }); function onDeviceReady() { try { cordova.plugins.notification.local.schedule({ text: "This is the text.", at: new Date(new Date().getTime() + 10000) }); } catch (e) { alert("Fail " + e); } } – Gandhi Jun 20 '16 at 09:14
  • @Gaafar Hi Gaafar, i did more or less the same mistake Zarkonnen did.Posted the answer. My bad :( – Gandhi Jun 21 '16 at 10:41
1

I tried out the same in iPhone 5s. Once i launched the notification app, nothing happened. Infact, the mistake i did was that i kept the app open in the background. Even after minutes, no notification showed up.

Finally, figured out that i had to go to home screen, swipe down the notification drawer from the home screen and click on Notifications tab to view the notification text. The sad part is that if the app is in foreground, the notification beep also dint worked :(

Moral: For iOS notifications, open the app and move it to background. Else if the app is in foreground, check for the notification in the notification drawer's Notifications tab

Gandhi
  • 11,875
  • 4
  • 39
  • 63
  • Yeah, I am not fully clear on how you're meant to reliably notify the user if the correct way depends on whether your app is currently open. :/ – Zarkonnen Jun 21 '16 at 16:42
  • @Zarkonnen Exactly zarkonnen. Infact I was investigating this issue for a day thinking that it dint worked :( That's why posted the answer for other's benefit. Please accept if it makes sense. Happy coding. Cheers – Gandhi Jun 21 '16 at 19:33