2

So I'm using this plugin (https://github.com/katzer/cordova-plugin-local-notifications) for my app to have local notifications however it is not working when I have tested it.

I followed this tutorial https://devdactic.com/local-notifications-ionic/ I have tested the app on Ionic View on both android and iOS. I press the buttons but nothing shows up.

I have tried switching $cordovaLocalNotification with cordova.plugins.notification.local. when trying to use the functions in the plugin but that didn't work.

For what it's worth, the plugin does not show up in the package.json file but it does show up when I run the 'cordova plugins' command.

EDIT 1: The following is an image taken from my iPhone after I clicked Add notification this is an error I got after I put the button click code in a try catch block

In my $ionicPlatform.ready(function(){...}), I have the following code

        if(window.cordova && window.cordova.plugins.notification) {

        alert('This alert doesn't fire');

      }

The alert doesn't appear which means window.cordova.plugins.notification is unavailable just like the picture indicates

EDIT 2: On the ionic forums it was suggested that the plugin is not working on the Ionic View app as it is not one of the supported plugins. Please refer to: https://forum.ionicframework.com/t/katzers-local-notification-plugin/86748

However it does work when running/testing on a device(android) instead of the Ionic View app.

Ayudh
  • 1,673
  • 1
  • 22
  • 55

1 Answers1

2

Add --save at the end of your command, something like:

cordova plugin add de.appplant.cordova.plugin.local-notification --save

It will add it to your config file.

Edit: Maybe you have error while using it. See error log by running the app with following command:

ionic run android -l -c

Finally running in the real device solved the issue.

Vahid Najafi
  • 4,654
  • 11
  • 43
  • 88
  • Are you sure there are something in `config.xml` that mentions to this plugin? If yes, maybe you have error. See edited part. – Vahid Najafi Apr 17 '17 at 07:56
  • The plugin is there in config.xml, and I cannot run android emulator on my comp as it lacks intel haxm acceleration that's why I have to test it using Ionic View – Ayudh Apr 17 '17 at 09:08
  • So, omit the emulator. If you connect your phone to your pc or laptop, you can run it directly to your phone and see the log in windows `cmd`. You should turn on your phone developer option first. (check if it's ok with `adb devices` command. It must show you some hashed strings.) – Vahid Najafi Apr 17 '17 at 09:57
  • I have tested it on my android device using 'ionic run android -l -c' and it is working. So can we assume that the problem is with the Ionic View app and that the code will work on real devices if deployed? – Ayudh Apr 17 '17 at 14:10
  • Yes. Finding the issue with ionic view is a bit difficult and annoying. For my case the reason was --save flag (but in ios). For native plugins, it's better to use real device with direct installation. I added the latest result to the answer. – Vahid Najafi Apr 17 '17 at 15:31