Receive notification when an application closes using ion

I use ionic2with FCM.

I get a notification when the application is running.

I need to be notified when the application is running or not.

How can i do this?

+6
source share
2 answers

You can use One-Signalone that solves your needs: here is a bit of code, how to initialize in ionic-2

Install OneSignal Cordova plugin through terminal

ionic cordova plugin add onesignal-cordova-plugin
 npm install --save @ionic-native/onesignal

Important note: make sure you import the provider into your app.module.ts as indicated on the Ionic Native website, e.g.

import {OneSignal} from '@ionic-native/onesignal';
@NgModule({
  ...
  providers: [
    ...
    OneSignal
    ...
  ]

})
export class AppModule { }

Taken from: Ionic-native

OneSignal.

app.ts, , , initializeApp():

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

constructor(private _OneSignal: OneSignal, private _platform: Platform) {
  startApp();
}

  startApp() {
    this._platform.ready().then(() => {
      this._OneSignal.startInit(appId, googleProjectId);
      this._OneSignal.inFocusDisplaying(this._OneSignal.OSInFocusDisplayOption.Notification);
      this._OneSignal.setSubscription(true);
      this._OneSignal.handleNotificationReceived().subscribe(() => {
        // handle received here how you wish.
      });
      this._OneSignal.handleNotificationOpened().subscribe(() => {
        // handle opened here how you wish.
      });
      this._OneSignal.endInit();        
    })    
  }

: :

appId OneSignal

googleProjectId FCM

0

, , , ( Firebase) , .

-, IOS, , ( ionic cordova build) REMOTE PUSH NOTIFICATIONS XCode. Android .

, , - , , , . cordova-plugin-firebase, notification title body, :

{ "notification": { "title": 'a title', "body": 'some text' }, "data": { "anydata1": 'data1', "anydata2": 'data2', "etc": 'etc' } }

phonegap-plugin-push . notification. .

0

All Articles