Using Local Notifications with ionic 2

New to Ionic , found a tutorial using Ionic 1

1.) I am looking for an ionic 2 version , can this be done with the cordova-plugin-local-notifications or is this built in like camera , scheduler etc.

2.) The notifications should be available even when the app is not running i.e. I need the app to run as a service (Noob question since I am new to app development space)

Take a look at this discussion

Hi, in the plugins github page says an quote:

For example, applications that depend on servers for messages or data can poll their servers for incoming items while running in the background

Here they talk about polling, the worst way of sync with the server since it consumes wifi or in the worst case the cellphones data connection (i mean the money they put into their cellphone to make calls, send messages or navigate through internet without wifi), what about web sockets? can they be used with this plugin? i don’t see any mention of this in both the forum article nor the plugin’s github page.

Thanks Richards, the link you sent is ionic 1 however , can it work with Ionic 2 ?

Sorry @jagsingh I pasted the wrong link. There was an Ionic 2 discussion about it somewhere. I can’t find it now - I will paste a link if I can find it.

1 Like

Any luck finding it. I’m trying to get this working as well.

Well, I just tried using the same plugin I’m using with my Ionic 1 apps : https://github.com/katzer/cordova-plugin-local-notifications

It should work, I got the successfully scheduled event, and even the app badge, but no lucky with the notification itself.

1 Like

Hi, somebody find anything for local notification in ionic 2?

Hi again https://github.com/katzer/cordova-plugin-local-notifications is work as ionic native.

add this : import {LocalNotifications} from 'ionic-native';

and use like this : LocalNotifications.schedule({ id: 1, text: "Single Notification" });

its work on android 5.

https://github.com/driftyco/ionic-native/tree/master/src/plugins in there lots of plugin rather than ionic web site doc.

1 Like

interesting! Is this preffered to Katzers plugin?

I’m using LocalNotifications, but I’m getting this error when trying to schedule multiple

TypeScript error: /Users/joshua.richards/projects/Symbicort30/app/pages/walkthrough/walkthrough.ts(196,32): Error TS2345: Argument of type '{ id: number; title: string; text: string; }[]' is not assignable to parameter of type 'Notification'.
  Types of property 'every' are incompatible.
    Type '(callbackfn: (value: { id: number; title: string; text: string; }, index: number, array: { id: nu...' is not assignable to type 'string'.

Any ideas?

@jjrchrds can you paste the code?

Hi @luchillo17,

did you found a solution for running in background and web sockets, wee need the same thing. We have a server with websockets and there should be a background process which is listing to it and give a local notification.
Can you give us some help or experiences?

Sorry man, i’ve only got into service workers, no web workers jet, and it was in an Angular 2 app, no Ionic.

this is verified and i tested it myself and its working on both ios and android read carefully and follow the steps :slight_smile: