Cordova Plugin not using ionic-native

I am trying to use local notifications cordova plugin from here.

I don’t want to use the ionic-native solution from here because it does not implement all features I need.

I have installed the cordova plugin like so
cordova plugin add https://github.com/katzer/cordova-plugin-local-notifications

Then I try to use after platform.ready like so…


   this.plt.ready().then(()=> {
         (<any>window).plugins.notification.local.schedule({
         id: 1,
         title: "Fitness App",
         text: "Timer done",
         priority: 1,
         at: Date.now()
       });
   });

I have tested this on a real device and in the browser (although I know it won’t work in the browser). In the browser it says that notification is not defined.

That’s because most cordova plugins don’t work in a browser environment. For those that do, you must add the “browser” cordova platform and build for it. Ordinary ionic serve won’t do. If the ionic-native shim doesn’t have some sort of functionality that the underlying plugin does, how about considering submitting a PR to add it? @ihadeed is quite receptive to community contributions.

I see, I’m not worried about it working in the browser anyway but I would like to get it working on my device. I want to test the local notifications and see if it does indeed have the functionality I desire if so then I would look into creating the pull request.

My issue now is that I cannot get the plugin to work with ionic. It does not seem to be finding the plugin.

Perhaps it would be a useful exercise to see if you can get it working following the ionic-native documentation.

I was initially using ionic-native and it doesn’t seem to have an option for priority which allows the notification to show as a heads up notification on android and it doesn’t seem to wake the device to display the notification. It was suggested on the github issues of the local notification plugin that it was possibly something ionic did to prevent it from waking the device. So that is why I am now trying to get the cordova plugin working. Apologies if this is confusing.

I managed to get it working just now with the following

declare var cordova;

(<any>cordova).plugins.notification.local.schedule({

Not sure if it has the functionality. So it may be the plugin itself. Thanks for the help

I would be surprised if you saw any difference in that sort of behavior whether using ionic-native or not. If there is an issue, I think it would have to be with Ionic itself, because as you can see in here, there is nothing that looks remotely like it would affect that sort of thing.

@rapropos as always, you’re right!

I did however try out an open PR for the local notifications which can be found here and this gave me heads up notifications using the following code:

 this.plt.ready().then(()=> {
         (<any>cordova).plugins.notification.local.schedule({
         id: 1,
         title: "Fitness App",
         text: "Timer done",
         headsup: true
         at: Date.now()
       });
   });

This did not solve the notification not triggering while the device is locked and the screen is dimmed but if I find a solution I will post back here for anyone who stumbles across this.

EDIT: It seems this has possibly fixed the issue of the notification not occurring when the device is locked.

Nice find! Is there a PR for these changes on the official Repo?

There is, Katzer, the owner of the plugin has stated this update a short time ago:
UPDATE (22.05.2017) I've released v0.8.5 with contains the code from ios10 branch as it is. I will start working on a new major version while dropping support for older SDKs. I will try to include all you PRs.

So it may take a while but should be merged at some point.

If there was a PR to link to, we could all leave a “+1” as a vote to get this integrated. Maybe it will be taken into consideration.

Good idea! There is a link to this here https://github.com/katzer/cordova-plugin-local-notifications/pull/999

1 Like

So if I understand correctly, the only missing option in Ionic Native is priority?

I opened an issue for that here: https://github.com/ionic-team/ionic-native/issues/1683

If there is anything else missing, let me know. I will fix it when I get a chance. Feel free to submit PRs if you would like to contribute too!

2 Likes

Thanks, yes it seems priority is missing and setting a priority to high is what allows the notification to be a heads up notification (for Android at least, I’ve read iOS has it by default but haven’t been able to check) which can be misleading.

I was about to open an issue on github about this, there is more functionality missing.
I want to use ‘actions’ inside these notifications, an action would be like an reply button when its an notification about an email or even typing an reply inside the notification (as in Android 7).
@ihadeed can you add that to your issue?

Hi can you also include this in milestone for ionic.

it’ll be great