1

Here is my code in app.js

import Vue from 'nativescript-vue'

import Home from './components/Home'

new Vue({
  render: h => h('frame', [h(Home)])
}).$start()

import { firebase } from '@nativescript/firebase-core'
import '@nativescript/firebase-auth'; // only needs to be imported 1x
import '@nativescript/firebase-storage';
import '@nativescript/firebase-messaging';


firebase().initializeApp().then(fbApp => {
  console.log("Firebase app initialized!", fbApp.name) //[DEFAULT]

  firebase().auth().addAuthStateChangeListener(async (user) => {
    console.log('user : '+user);
    if (!user) {
      console.log("firebase.auth done");
    } else {
      console.log("firebase.auth else done");
    }
  })

})

// Get the device token
firebase().messaging()
  .getToken()
  .then(token => {
    console.log(token);
  });

firebase()
  .messaging()
  .onMessage(async remoteMessage => {
    console.log('A new FCM message arrived!'+JSON.stringify(remoteMessage));
  });

firebase().messaging().onBackgroundMessage

I want the FCM alarm to work in the background, and when I click the alarm, I want the console.log to show what kind of message I got. But I don't have idea what function I use to. Please Help.

1 Answer 1

0

I used those codes.

//background notification
    firebase().messaging().onNotificationTap(async message =>{
      var body = message.notification.body;
      this.saveHistory(message.notification.title,body);
      this.$navigateTo(Detail,{
        props:{
          shtUrl : body
        }
      });
firebase().messaging().showNotificationsWhenInForeground = true;
    //foreground notification
    firebase().messaging().onMessage(async remoteMessage => {
      let _this = this;
      this.saveHistory(remoteMessage.notification.title,remoteMessage.notification.body);

      Dialogs.confirm({
        title: remoteMessage.notification.title,
        message: remoteMessage.notification.body,
        okButtonText: "Go",
        cancelButtonText: "No"
      }).then(function (result) {
        if(result){
          _this.$navigateTo(Detail,{
            props:{
              shtUrl : remoteMessage.notification.body
            }
          });
        }
      });
    });
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.