question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Notification message not shown when app is in the background

See original GitHub issue

Hi, I have a problem using this plugin, could use some help here…

I’m using curl to post a notification message to Firebase, like so:

Headers:

Content-Type:application/json
Authorization:key=[MY_AUTH_KEY]

JSON:

{
    "to" : "[MY_FIREBASE_KEY]",
    "content_available": true,
    "notification" : {
        "body" : "great match!",
        "title" : "Portugal vs. Denmark",
        "click_action": "helloworld",
        "icon": "notification_default",
        "sound" : "default",
	"priority": "high",
	"badge": 1
    }
}

Using the app sample code downloaded from Firebase, this works… So I know that my Firebase key and my authorization key are correct (and also my Apple certificate). When the app is in the background, I receive a sound and a notification in the notification centre on iOS.

Now I’m trying to use my own sample code, with the following result: When the app is in the foreground, an event is triggered and I receive the data, so that works perfectly! Now when the app is in the background, I would expect that (as in the sample above), iOS will play a sound, show a badge and display a notification in the notification centre…but it does not! Nothing happens…

Is something wrong with the plugin? Can anybody point me in the right direction?

Source code (main.ts) below:

// this import should be first in order to load some required settings (like globals and reflect-metadata)
import { platformNativeScriptDynamic } from "nativescript-angular/platform";

import { AppModule } from "./app.module";

import firebase = require("nativescript-plugin-firebase");

firebase.init({
  // Optionally pass in properties for database, authentication and cloud messaging,
  // see their respective docs and 'iOSEmulatorFlush' to flush token before init.
  iOSEmulatorFlush: true,
  onPushTokenReceivedCallback: function(token) {
      console.log("Firebase push token: " + token);
  },
  onMessageReceivedCallback: function(message) {
      console.dump(message);
      console.log("Title: " + message.title);
      console.log("Body: " + message.body);
      // if your server passed a custom property called 'foo', then do this:
//      console.log("Value of 'foo': " + message.foo);
    }
}).then(
  (instance) => {
    console.log("firebase.init done");
  },
  (error) => {
    console.log("firebase.init error: " + error);
  }
);

platformNativeScriptDynamic().bootstrapModule(AppModule);

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:57 (25 by maintainers)

github_iconTop GitHub Comments

3reactions
EddyVerbruggencommented, Jan 17, 2017

@sudhanshu-15 I’m looking at this later today with the demo app.

1reaction
EddyVerbruggencommented, Jan 24, 2017

@simonettoa You’re doing everything right, except you need to remove <key>FirebaseAppDelegateProxyEnabled</key><false/> from app/app_resources/ios/xx.plist

Read more comments on GitHub >

github_iconTop Results From Across the Web

Firebase onMessageReceived not called when app in ...
When app is in background, Notification messages are delivered to the system tray. If the app is in the foreground, messages are handled...
Read more >
Firebase messaging not display "heads up" notification on ...
I am implementing messaging functionality and can't seem to find working solution for both foreground & background notifications.
Read more >
Notifications Not Shown - Mobile Push
The following are reasons why notifications may show as "Delivered" on the OneSignal dashboard or API, but are not visible on your device....
Read more >
Send a test message to a backgrounded app | Firebase Cloud ...
Send a test notification message · Install and run the app on the target device. · Make sure the app is in the...
Read more >
Flutter Firebase Foreground and Background Messaging
How to handle notification when app in background in Firebase Flutter firebase cloud messaging, flutter firebase messaging notifications, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found