Giter Club home page Giter Club logo

Comments (14)

williamjuan027 avatar williamjuan027 commented on June 14, 2024 1

@triniwiz It turns out to be the initialization issue. In an Angular project, initializing it in the main.ts resolves the issue. Below is the code I used to initialize the plugin.

// main.ts

import { firebase } from '@nativescript/firebase-core';
import '@nativescript/firebase-messaging';

const firebaseInit = firebase().initializeApp();
if (firebaseInit) {
  firebase().messaging();
}

from firebase.

felixkrautschuk avatar felixkrautschuk commented on June 14, 2024 1

@triniwiz I believe it works now on my side, even with our custom app delegate and with initializing Firebase in the app launch event.

The only change: I added the following line after initializing firebase:

firebase().messaging().registerDeviceForRemoteMessages();

I did not find this method in the docs but my IDE suggested this method from the plugins API ;)
When adding this line, notifications are shown as expected and both callbacks are triggered.

from firebase.

triniwiz avatar triniwiz commented on June 14, 2024 1

You should call that register after requesting permission

from firebase.

DieOver avatar DieOver commented on June 14, 2024

Even though I receive notifications when app is in background, onMessage callback is never triggered, neither on foreground nor on background. This works on android but not on iOS. I use iOS 15.

I'm having exacly the same issue, i can receive push when background, but not when foreground throght onMessage method..

searching the plugins code, i see that a need to set showNotificationsWhenInForeground to true.. but not working anyway...

I'm using iOS 14 and 15

from firebase.

williamjuan027 avatar williamjuan027 commented on June 14, 2024

@triniwiz I also ran into this issue and did some more testing to try to figure out the root cause of the problem. Here are a few of my findings.

  1. If the app is in the background or closed, I get the notification. However, tapping on the notification to open the app doesn't trigger any callback (I think the previous firebase plugin calls the onMessage callback when this happens).
  2. When the app is in the foreground, the notification isn't displayed and onMessage is never called (both with firebase().messaging().showNotificationsWhenInForeground set to true and false)
  3. I tested with and without the Firebase Authentication plugin, both yielding the same result as above.

Further investigation, I found that only 3 methods from the Firebase Messaging plugin's AppDelegate is being called:

  • applicationDidRegisterForRemoteNotificationsWithDeviceToken
  • sharedInstance getter
  • observe

None of the methods from UNUserNotificationCenterDelegate is ever called.

I used the latest version that was released today (alpha36) to test these.

Hope that helps :)

from firebase.

shirakaba avatar shirakaba commented on June 14, 2024

Just a quick uninformed thought, though it may be completely off the mark. Firebase relies on a lot of swizzling of the AppDelegate; does NativeScript do anything odd with its own handling of AppDelegate that might cause the swizzling to fail?

from firebase.

triniwiz avatar triniwiz commented on June 14, 2024

I think might be a matter of when firebase().messaging() is called since (in this demo it’s called before the app launches) it sets up a couple things

from firebase.

CatchABus avatar CatchABus commented on June 14, 2024

@triniwiz It turns out to be the initialization issue. In an Angular project, initializing it in the main.ts resolves the issue. Below is the code I used to initialize the plugin.

// main.ts

import { firebase } from '@nativescript/firebase-core';
import '@nativescript/firebase-messaging';

const firebaseInit = firebase().initializeApp();
if (firebaseInit) {
  firebase().messaging();
}

What about apps that need messaging only after user authentication?

from firebase.

triniwiz avatar triniwiz commented on June 14, 2024

Please update to the latest version

from firebase.

felixkrautschuk avatar felixkrautschuk commented on June 14, 2024

@triniwiz I have a similar problem on iOS, even after installing the latest firebase-messaging plugin (1.0.0-alpha.41).

When testing the push notifications in Simulator using an apns file like this:

{
    "Simulator Target Bundle": "np.com.sagunrajlage.TestPushNotifications",
    "aps": {
        "alert": "Push Notifications Test",
        "sound": "default",
        "badge": 1
    }
}

(which is descriobed here https://betterprogramming.pub/how-to-send-push-notifications-to-the-ios-simulator-2988092ba931), then I see the notification in Simulator in all app states (foreground, background and closed).
BUT: the onMessage callback is never called and when tapping the notification, the onNotificationTap callback is not called as well.

When testing the push notifications on a real iOS device with our real server or sending a message via Firebase Console directly to the device, I do not even see a notification (no matter which state the app has) and no callback is called.
When doing the same stuff using the old nativescript firebase plugin, everything works as expected on iOS.

On Android the new firebase messaging plugin seems to work as expected.

from firebase.

triniwiz avatar triniwiz commented on June 14, 2024

@felixkrautschuk I didn't know about the sim notifications , I can see this being an issue since there are some checks in the code that may cause issues with the sim as for the issue with the real device does the app use any custom delegates by chance ?

from firebase.

triniwiz avatar triniwiz commented on June 14, 2024

Another thing please try calling firebase().initializeApp(); before the app launches

from firebase.

felixkrautschuk avatar felixkrautschuk commented on June 14, 2024

@triniwiz thanks for your reply. I uncommented the custom delegate. And I moved the firebase().initializeApp(); to the beginning of app.js but unfortunately this does not help.

from firebase.

triniwiz avatar triniwiz commented on June 14, 2024

Do you have a sample app of how your app is setup ? The best I can do w/o an app is point you to the demo app in this project

from firebase.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.