Ionic 2 push notifications using FCM


Patrick Ian Co

I am implementing push notifications on my Android Ionic 2 App using Ionic Native FCM

When I get the notification in the foreground it works, but when I get the notification in the background, if I click it, nothing happens.

app.component.ts

firebaseInit(){
  //Firebase
  this.fcm.subscribeToTopic('all');

  this.fcm.getToken()
    .then(token => {
      console.log(token);
      this.nativeStorage.setItem('fcm-token', token);
  });

  this.fcm.onNotification().subscribe(
    data => {
      console.log("NOTIF DATA: " + JSON.stringify(data));
      if(data.wasTapped){
        this.nav.push(MemoViewPage, {memo: {_id: data.memo_id}})
        console.info('Received in bg')
      }else{
        let alert = this.alertCtrl.create({
          title: data.subject,
          message: "New memorandum",
          buttons: [
            {
              text: 'Ignore',
              role: 'cancel'
            },
            {
              text: 'View',
              handler: () => {
                this.nav.push(MemoViewPage, {memo: {_id: data.memo_id}})
              }
            }
          ]
        });

        alert.present();
        console.info('Received in fg')
      }
  });

  this.fcm.onTokenRefresh()
    .subscribe(token => {
      console.log(token);
  })
}

The if(data.wasTapped)notification condition does not go off once I click on the system tray.

edit

The app will open, but only in the home page not opening the specified page I set, i.e.this.nav.push(MemoViewPage, {memo: {_id: data.memo_id}})

I also can't get notifications when the app is killed or not running.

Gitting

You can use pushplugin instead FCM.

this.push.createChannel({
 id: "testchannel1",
 description: "My first test channel",
 importance: 3
}).then(() => console.log('Channel created'));

You can then use pushObjects to specify the notification's needs, such as sounds, ions, etc.

const options: PushOptions = {
   android: {},
   ios: {
       alert: 'true',
       badge: true,
       sound: 'false'
   },
   windows: {},
   browser: {
       pushServiceURL: 'http://push.api.phonegap.com/v1/push'
   }
};

After that, you can easily get notifications whether you are using the app or not

const pushObject: PushObject = this.push.init(options);

pushObject.on('registration').subscribe((registration: any) => this.nativeStorage.setItem('fcm-token', token));

pushObject.on('notification').subscribe((notification: any) => console.log('Received a notification', notification));

You can use the options forceShow:truein pushObject initthe app whether the app is in use or not showing notifications.

And, as soon as you click on the notification, the app receives the notification payload and sets the app home page as the default home page.

Related


Push notifications using Ionic Framework

Arivan Bastos I'm trying to implement push notifications using Ionic and I'm confused. So far I have tried the following alternatives without success: ion push Seems to be the best solution. It "emulates" the notification in the browser, making testing easy. T

Push notifications using FCM and PHP

Linu Sherin I am trying to send push notifications from my react native app using fcm and php as server. Below is my code to receive server notification in React. pushNotification.js import React, { Component } from "react"; import FCM from "react-native-fcm"

iOS push notifications using Firebase FCM token

username This is a more question about the industry standard way of sending iOS push notifications using Firebase FCM tokens. I don't have my own push server and would like to take advantage of Firebase Cloud Functions. I'm building an app with chat functional

Push notifications on IONIC 2 using PHP server side

Cardi Time Master I'm doing an app with ionic 2 angular 2 and Typescript in which I need to implement push notifications. I have used local notifications, I use ionic 2 Dashboard to send notifications to all app users. But I really didn't find how to automate

Unable to receive push notifications in foreground using FCM

Kunal Kushwaha I've been trying to get Firebase push notifications in my app. I have tried everything on the internet but can't find a solution. I keep getting notifications in the background, but I can't get notifications when the App is in the foreground. Bu

Using FCM Push Notifications on DevExtreme/Phonegap

Piero Alberto I developed my application using DevExtreme, a multiplatform tool based on PhoneGap. Now I'm trying to manage push notifications using to phonegap-plugin-push. My first simple goal is to send and receive some notifications from FCM (Firebase Clou

Receive push notifications in IOS using gem fcm

Chakreshwar Sharma I gem 'fcm'use to send push notifications. I can send notification on android but i don't get it in IOS. I am using the following code: fcm = FCM.new('my key', timeout: TIMEOUT) options = { data: { title: 'My title', mess

Android FCM push notifications using meteor

user31039 I referenced the following documents : https://github.com/raix/push and https://github.com/raix/push/blob/master/docs/ANDROID.md . Among them I found that I have to add part of the code on the server side of the application. code show as below: Push.

Cordova push notifications android and ios using FCM

Rahus I'm new to Cordova, is there anyone working on push notifications for Cordova hybrid apps. Please recommend me a push notification plugin? Rahul.sapkal23 cordova-plugin-firebase is a nice plugin for cordova firebase implementation. I am working on this p

Push notifications using Ionic Framework

Arivan Bastos I'm trying to implement push notifications using Ionic and I'm confused. So far I have tried the following alternatives without success: ion push Seems to be the best solution. It "emulates" the notification in the browser, making testing easy. T

Push notifications using Ionic Framework

Arivan Bastos I'm trying to implement push notifications using Ionic and I'm confused. So far I have tried the following alternatives without success: ion push Seems to be the best solution. It "emulates" the notification in the browser, making testing easy. T

Push notifications using FCM and PHP

Linu Sherin I am trying to send push notifications from my react native app using fcm and php as server. Below is my code to receive server notification in React. pushNotification.js import React, { Component } from "react"; import FCM from "react-native-fcm"

Unable to receive push notifications in foreground using FCM

Kunal Kushwaha I've been trying to get Firebase push notifications in my app. I have tried everything on the internet but can't find a solution. I keep getting notifications in the background, but I can't get notifications when the App is in the foreground. Bu

Ionic 2 push notifications using FCM

Patrick Ian Co I am implementing push notifications on my Android Ionic 2 App using Ionic Native FCM When I get the notification in the foreground it works, but when I get the notification in the background, if I click it, nothing happens. app.component.ts fir

iOS push notifications using Firebase FCM token

username This is a more question about the industry standard way of sending iOS push notifications using Firebase FCM tokens. I don't have my own push server and would like to take advantage of Firebase Cloud Functions. I'm building an app with chat functional

Push notifications using FCM and PHP

Linu Sherin I am trying to send push notifications from my react native app using fcm and php as server. Below is my code to receive server notification in React. pushNotification.js import React, { Component } from "react"; import FCM from "react-native-fcm"

Flutter push notifications by topic using FCM

Fahmi Sawaha hello i am new to flutter and trying to get push notifications in flutter, i have successfully subscribed a user to a topic and sent a notification by topic via firebase console, what i want to do is to set for admin A button in the app, when they

Push notifications using Ionic Framework

Arivan Bastos I'm trying to implement push notifications using Ionic and I'm confused. So far I have tried the following alternatives without success: ion push Seems to be the best solution. It "emulates" the notification in the browser, making testing easy. T

Push notifications using Ionic Framework

Arivan Bastos I'm trying to implement push notifications using Ionic and I'm confused. So far I have tried the following alternatives without success: ion push Seems to be the best solution. It "emulates" the notification in the browser, making testing easy. T

Push notifications using FCM and PHP

Linu Sherin I am trying to send push notifications from my react native app using fcm and php as server. Below is my code to receive server notification in React. pushNotification.js import React, { Component } from "react"; import FCM from "react-native-fcm"

Push notifications using FCM and PHP

Linu Sherin I am trying to send push notifications from my react native app using fcm and php as server. Below is my code to receive server notification in React. pushNotification.js import React, { Component } from "react"; import FCM from "react-native-fcm"

Ionic 2 push notifications using FCM

Patrick Ian Co I am implementing push notifications on my Android Ionic 2 App using Ionic Native FCM When I get the notification in the foreground it works, but when I get the notification in the background, if I click it, nothing happens. app.component.ts fir

Ionic 2 push notifications using FCM

Patrick Ian Co I am implementing push notifications on my Android Ionic 2 App using Ionic Native FCM When I get the notification in the foreground it works, but when I get the notification in the background, if I click it, nothing happens. app.component.ts fir

iOS push notifications using Firebase FCM token

username This is a more question about the industry standard way of sending iOS push notifications using Firebase FCM tokens. I don't have my own push server and would like to take advantage of Firebase Cloud Functions. I'm building an app with chat functional

Unable to receive push notifications in foreground using FCM

Kunal Kushwaha I've been trying to get Firebase push notifications in my app. I have tried everything on the internet but can't find a solution. I keep getting notifications in the background, but I can't get notifications when the App is in the foreground. Bu