How to make Ionic Cordova notification?

Asked

Viewed 706 times

-1

I need to make notifications like facebook on mobile phones, I’m making an app using Angularjs, Ionic, jquery, javascript and nodejs... is there any simple way to do this?

2 answers

1


You can use the Onesignal, it is very simple to use, besides the documentation being very complete. Follow a simple example.

constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen) {
  platform.ready().then(() => {
    statusBar.styleDefault();
    splashScreen.hide();

    var notificationOpenedCallback = function(jsonData) {
      console.log('notificationOpenedCallback: ' + JSON.stringify(jsonData));
    };

    window["plugins"].OneSignal
      .startInit("YOUR_APPID", "YOUR_GOOGLE_PROJECT_NUMBER_IF_ANDROID")
      .handleNotificationOpened(notificationOpenedCallback)
      .endInit();
  });
}

You can check more on your own documentation.

1

If your project is in Ionic 3 you can use Ionic Native....

import { OneSignal } from '@ionic-native/onesignal';

constructor(private oneSignal: OneSignal) { }

...

this.oneSignal.startInit('b2f7f966-d8cc-11e4-bed1-df8f05be55ba', '703322744261');

this.oneSignal.inFocusDisplaying(this.oneSignal.OSInFocusDisplayOption.InAppAlert);

this.oneSignal.handleNotificationReceived().subscribe(() => {
 // do something when notification is received
});

this.oneSignal.handleNotificationOpened().subscribe(() => {
  // do something when a notification is opened
});

this.oneSignal.endInit();

Can also look at the documentation.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.