-
-
Notifications
You must be signed in to change notification settings - Fork 50
[firebase-messaging][Android] trigger onNotificationTap callback on app launch from a notification #42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Please try again with the latest alpha |
I just found this, is this the recommended way for the Angular flavor? Originally posted by @williamjuan027 in #24 (comment)
|
@jessorlisa There was a recent update that made the // main.ts
import { firebase } from '@nativescript/firebase-core';
import '@nativescript/firebase-messaging';
firebase().initializeApp().then((app) => {
const firebaseApp = app; // optional - if you need reference to the firebase app :)
}); |
@williamjuan027 Thanks a lot. I just realized that studying the source. 😊 However moving the initialization to |
@jessorlisa Yes, you're right. I just tested that out on my end, and |
@triniwiz When I test this on Android, I found out that if I add the // main.ts
import { firebase } from '@nativescript/firebase-core';
import '@nativescript/firebase-messaging';
firebase().initializeApp().then(app =>{
firebase().messaging().onNotificationTap((message) => {
// gets called when tapping on the notification while the app is closed, but not when the app is in the background
console.log('[Main][onNotificationTap]', message);
});
}); // messaging.service.ts
import { Injectable } from '@angular/core';
import { firebase } from '@nativescript/firebase-core';
@Injectable({
providedIn: 'root'
})
export class MessagingService {
init(): void {
firebase().messaging()
.requestPermission()
.then(() => {
firebase().messaging().onMessage((message) => {
// gets called when an fcm is received while app is in the foreground
console.log('[MessagingService][onMessage]', message);
});
firebase().messaging().onNotificationTap((message) => {
// gets called when a notification tap while app is in the background
console.log('[MessagingService][onNotificationTap]', message);
});
})
}
} Hope this helps :) |
I just did a quick check, the same problem seems to apply to iOS. |
@jessorlisa I was seeing it come in under |
@williamjuan027 None is called - but maybe because I currently add the handlers in a service, not the main.ts. Will do another test tomorrow. |
Sorry for the delay: Setup 1: Angular project, handlers added in a service
Setup 2: Angular project, handlers added in main.ts before bootstrap
I also noticed that on iOS you have to register the device for remote messages after requesting permission, otherwise it does not work at all. Can anybody confirm this? firebase().messaging()
.requestPermission()
.then(() => {
// seems to be necessary for iOS to work?
if (isIOS) {
firebase().messaging()
.registerDeviceForRemoteMessages()
.catch((e) => {
console.error(e);
});
}
}); |
I can confirm. FCM was not working until I added this call. It's also mentioned in #24. Spent way too long to discover this 😄 |
@triniwiz Is the 3rd scenario as mentioned below supposed to work with the latest version (1.1.2)?
As of right now I am still having issues in that case. |
It should I updated the angular demo to test ... |
I followed your demo exactly, still not working. No handler is called if the app is closed and the handlers are added in a service. Looking at the commit message It seems only the missing
But I will do another check ... |
I am afraid I have the same situation as back in February. I tried to follow the demo exactly. |
Try the following
|
I set up a simple demo project to show the current issue: All relevant information can be found in the "Issue description" and "Reproduction" section. Let me know if
On a side note: |
@triniwiz Could you reopen this, me and @jessorlisa are having this issue.
This seems to be an issue with Angular only since no one else is reporting it, the demo project is actually the same issue I'm getting. |
Hey @triniwiz, I have read the thread here, but I am unsure what is the solution supposed to be. Notification handlers are still not being invoked if they are registered within an Angular service. Moving them to |
This shouldn't be an issue again with the latest versions |
It's still the happening for me on:
On android when the app is closed, notification tap will not invoke the callback, unless I move out Update: Seems to be working with
in |
Finally, firebase was instantiated to late. I initialized firebase before Vue and also made sure that
was wrapped in a then promise pattern. It all works now. |
When the app is launched from a closed state with a notification tap
onNotificationTap
is not called. Would be great to have a way to enable this behavior or have it on by default.@nativescript/firebase
handles this here https://github.com/EddyVerbruggen/nativescript-plugin-firebase/blob/2fe6fe6156f2665b2017c711d92a38f593c3bbee/src/messaging/messaging.android.ts#L52The text was updated successfully, but these errors were encountered: