Skip to content
This repository has been archived by the owner on Apr 4, 2023. It is now read-only.

app not receiving push notifications from firebase #1440

Closed
aquinn637 opened this issue Oct 22, 2019 · 13 comments
Closed

app not receiving push notifications from firebase #1440

aquinn637 opened this issue Oct 22, 2019 · 13 comments

Comments

@aquinn637
Copy link

I’m working on trying to get push notifications working on my project. I’m working on a new project with NativeScript and Angular 8.

I have created a free account with Firebase: https://console.firebase.google.com/
I linked my app id to the Firebase project and added Android. I downloaded the file ‘google-services.json ’ and put it in app/App_Resources/Android/google-services.json

I found a plugin for NativeScript for using Firebase:
https://github.com/EddyVerbruggen/nativescript-plugin-firebase

I followed the steps on both the firebase console and on the plugin github page but I’m not getting any notifications through on my phone.

How can I get my app to receive the push notifications?

Here is my app.components.ts file:

import { Component, OnInit } from "@angular/core";
const firebase = require("nativescript-plugin-firebase");
//import * as firebase from "firebase";

@Component({
    selector: "ns-app",
    templateUrl: "./app.component.html"
})
export class AppComponent implements OnInit {

    ngOnInit() {
      firebase.init({

        showNotifications: true,
        showNotificationsWhenInForeground: true,

        // Optionally pass in properties for database, authentication and cloud messaging,
        // see their respective docs.

        onPushTokenReceivedCallback: (token) => {
          console.log('[Firebase] onPushTokenReceivedCallback:', { token });
        },

        onMessageReceivedCallback: (message) => {
          console.log('[Firebase] onMessageReceivedCallback:', { message });
        }

      }).then(
        () => { console.log("firebase.init done"); },
        error => {
          console.log(`firebase.init error: ${error}`);
        }
      );
    }

}

package.json:

{
  "nativescript": {
    "id": "org.nativescript.FireBaseTest2",
    "tns-android": {
      "version": "6.1.2"
    },
    "tns-ios": {
      "version": "6.1.0"
    }
  },
  ....

Here are my push notification attempts:

Screenshot (77)

@EddyVerbruggen
Copy link
Owner

Can you share that project with me? And are you running on a real device?

@aquinn637
Copy link
Author

@EddyVerbruggen Yes, I'm running on a real Android device. How can I share my project with you?

@EddyVerbruggen
Copy link
Owner

Push a version of your that shows the problem to Github. Please strip it of any unrelated things..

@aquinn637
Copy link
Author

@aquinn637
Copy link
Author

@EddyVerbruggen This is the code in my app.component file: ngOnInit() {
firebase.init({

    showNotifications: true,
    showNotificationsWhenInForeground: true,

    // Optionally pass in properties for database, authentication and cloud messaging,
    // see their respective docs.
    
    onPushTokenReceivedCallback: (token) => {
      console.log('[Firebase] onPushTokenReceivedCallback:', { token });
    },

    onMessageReceivedCallback: (message) => {
      console.log('[Firebase] onMessageReceivedCallback:', { message });
    }

  }).then(
    () => { console.log("firebase.init done"); },
    error => {
      console.log(`firebase.init error: ${error}`);
    }
  );
}

I am getting some console log output:

JS: firebase.init done
JS: [Firebase] onPushTokenReceivedCallback: {
JS: "token": "dUtx4IEaz5E:APA91bE3qwJnjHVzOyFekkktpq8gDeDl5cXvTKhU3Zm9ERmuMPdBd_OsaqlLJilWzjnWsLiAnrB0fj8UkVVIEp6Od7hzwCNwwU41D5Y8vUQfhq3LZV_ZcFLs9Gp4QZU8mpxeVGtgg7tH"
JS: }
JS: [Firebase] onMessageReceivedCallback: {
JS: "message": {
JS: "foreground": true,
JS: "from": "346123413786",
JS: "title": "Hello5",
JS: "body": "Hello5, this is a test",
JS: "data": {}
JS: }
JS: }

But the notifications do not show up on the device. Android 5.0 SM-N9005

@aquinn637
Copy link
Author

@EddyVerbruggen I got one notification but it was only when the app was in the background. Not when the app was in the foreground.

@EddyVerbruggen
Copy link
Owner

Let's continue in your repo.

@vytautas-pranskunas-
Copy link

Hi, do you have this sorted out?
I also get notifications only in console in onMessageReceivedCallback but notifications are not showing

@manojdcoder
Copy link

@vytautas-pranskunas-

  • Are you testing on real device?
  • Notification never appear Or only when app is on foreground?

@vytautas-pranskunas-
Copy link

  • Not sure what does that mean "testing on real device" because i have run "tns run adnroid" so emulator started but by using "preview" i also have it running on my phone. So is it real or not?

  • Notifications appear only in console never on device or emulator

@vytautas-pranskunas-
Copy link

I wonder maybe this is because i never got notification about push notification permissions?

@felicks
Copy link

felicks commented May 5, 2020

I have the same issue

@NazimMertBilgi
Copy link

Will the emulator not work in any way?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants