Comments (14)
@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.
@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.
You should call that register after requesting permission
from firebase.
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.
@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.
- 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). - When the app is in the foreground, the notification isn't displayed and
onMessage
is never called (both withfirebase().messaging().showNotificationsWhenInForeground
set totrue
andfalse
) - 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
getterobserve
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.
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.
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.
@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.
Please update to the latest version
from firebase.
@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.
@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.
Another thing please try calling firebase().initializeApp();
before the app launches
from firebase.
@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.
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)
- `const admin = require('firebase-admin')` crashes with `TypeError: Cannot read properties of undefined (reading 'env')` HOT 3
- Displaying alert after canceling from firebase().ui().show() causes exception HOT 2
- [firebase-crashlytics] Fatal errors aren't sent to Firebase console HOT 2
- [Firebase-storage][Android] Error: An unknown error occurred, please check the HTTP result code and inner exception for server response. HOT 1
- Migrating from legacy FCM APIs to HTTP v1 HOT 3
- [firebase-crashlytics AND firebase-messaging] iOS app crashes upon launch HOT 6
- Expost remove listeners for firebase messaging
- Support for new version of Firebase HOT 6
- Error calling setConsent() in the last version. HOT 1
- [firebase 3.2.x] Android "default FirebaseApp is not initialized" HOT 1
- Foreground and background notifications OK, but what about when the app is killed?
- firebase["ServerValue"].TIMESTAMP how do we use this in a new library HOT 1
- iOS build fails with "value of optional type ... must be unwrapped" error
- [@nativescript/firebase-messaging-core][android] Error when trying to register device HOT 2
- The operation couldn't be completed. No APNS token specified before fetching FCM token HOT 1
- [@nativescript/firebase-messaging-core][iOS] get notification from third-party service
- Cannot disable Ad ID support with `$NSFirebaseAnalyticsWithoutAdIdSupport=true`
- [@nativescript/firebase-performance][android] Not monitoring network requests HOT 1
- [@nativescript/firebase-admob] Warning on exports
- [@nativescript/firebase-storage] getDownloadURL closes app in IOS without error
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from firebase.