Hi guys.
I have a problem in my second build of the app in Android. When the app is running for first time in device works good getting de token device for push notifications. But when I make any changes in code or reopen the app the function getCurrentPushToken() shows this error:
Uncomment firebase-messaging in the plugin's include.gradle first
A temporary solution is saving the token in cache or ApplicationSettings, but I don't thing is a right solution. Any Ideas?
{
"nativescript": {
"id": "com.emeraldStudio.app",
"tns-android": {
"version": "4.2.0"
},
"tns-ios": {
"version": "4.2.0"
}
},
"description": "NativeScript Application",
"license": "SEE LICENSE IN
"repository": "
"scripts": {
"lint": "tslint "app/*/.ts""
},
"dependencies": {
"@angular/animations": "~6.1.0",
"@angular/common": "~6.1.0",
"@angular/compiler": "~6.1.0",
"@angular/core": "~6.1.0",
"@angular/forms": "~6.1.0",
"@angular/http": "~6.1.0",
"@angular/platform-browser": "~6.1.0",
"@angular/platform-browser-dynamic": "~6.1.0",
"@angular/router": "~6.1.0",
"google-polyline": "^1.0.0",
"nativescript-accordion": "^5.0.4",
"nativescript-angular": "~6.1.0",
"nativescript-feedback": "^1.2.0",
"nativescript-geolocation": "^4.3.0",
"nativescript-gif": "^4.0.1",
"nativescript-google-maps-sdk": "^2.6.1",
"nativescript-google-places-autocomplete": "^1.0.3",
"nativescript-loading-indicator": "^2.4.0",
"nativescript-plugin-firebase": "^7.1.0",
"nativescript-social-share": "^1.5.1",
"nativescript-theme-core": "~1.0.4",
"nativescript-ui-sidedrawer": "~4.2.0",
"reflect-metadata": "~0.1.10",
"rxjs": "~6.2.0",
"tns-core-modules": "~4.2.0",
"zone.js": "~0.8.18"
},
"devDependencies": {
"codelyzer": "~4.3.0",
"nativescript-dev-sass": "~1.6.0",
"nativescript-dev-typescript": "~0.7.0",
"nativescript-dev-webpack": "~0.15.0",
"tslint": "~5.11.0",
"typescript": "~2.7.2",
"@angular/compiler-cli": "~6.1.0",
"@ngtools/webpack": "~6.1.0"
},
"readme": "NativeScript Application"
}
Thanks in advance!
Same for me, any solutions?
Can anyone show this issue in a repo, so I can reproduce it?
Some ideas how to resolve this problem? I have same issue on 7.1.2.
I mentioned this in the ticket I closed above (#932), but I believe a change between 6.8.0 and 6.8.1 caused this. I can not test without altering my config because one of the issues was resolved by 7.1.2, but on 6.8.1 if I were to enable authorization then I get this issue.
I've been trying to replicate with push-demo in this repo but have not had any success so far. Comparing the built-out platforms directories, the demo-push contains stuff seemingly related to the plugin at app/build/intermediates/multi-dex/debug/maindexlist.txt, while my project does not even have a `app/build/intermediates/multi-dex folder.
I have no idea if that is helpful, but please let me know if there is anything else I can investigate.
I'm facing the same issue. I migrated from the other deprecated plugin for push notification, but not even able to init and get a token.
Take a look at demo-push in this repo. If you can鈥檛 make it work share a repo and I might take a look.
@james-criscuolo u have right. I went back to 6.8.0 (6.8.1 is bugged with #933 ) and there is no issue on this version. Maybe that will be helpful for u @EddyVerbruggen
Confirm issue still not fix on 7.1.3
Back to 6.8.0 there is no problem.
Please. Share. A. Repo.
Please. Share. A. Repo.
I have same problem. Most funny things that demo-push working fine. I try to prepare a repo today.
Please. Share. A. Repo.
Please take a look https://github.com/sokolovstas/demo-push-fail
JS: Added addOnMessageReceivedCallback
JS: Failed to registerForPushNotifications: Uncomment firebase-messaging in the plugin's include.gradle first
JS: Unhandled Promise rejection: Uncomment firebase-messaging in the plugin's include.gradle first ; Zone: <root> ; Task: Promise.then ; Value: Uncomment firebase-messaging inthe plugin's include.gradle first undefined
I'm facing the same issue. I migrated from the other deprecated plugin for push notification, but not even able to init and get a token.
Issue doesn't appear on version 6.8.0
I'll use that for now.
Facing same issue on 7.1.5
Using this for _lite_ mode of messaging following https://github.com/EddyVerbruggen/nativescript-plugin-firebase/blob/master/docs/NON_FIREBASE_MESSAGING.md
Share a repo. 7.1.5 wasn鈥檛 intended to fix this.
@EddyVerbruggen here:
Please. Share. A. Repo.
Please take a look https://github.com/sokolovstas/demo-push-fail
JS: Failed to registerForPushNotifications: Uncomment firebase-messaging in the plugin's include.gradle first JS: Unhandled Promise rejection: Uncomment firebase-messaging in the plugin's include.gradle first ; Zone: <root> ; Task: Promise.then ; Value: Uncomment firebase-messaging inthe plugin's include.gradle first undefined
@DeepikaKochar I'm already working with @sokolovstas in their repo. I'm asking @btulsi-ygrene for one as well because I can't tell whether or not it's the exact same issue.
@DeepikaKochar I'm already working with @sokolovstas in their repo. I'm asking @btulsi-ygrene for one as well because I can't tell whether or not it's the exact same issue.
Oh.. @EddyVerbruggen Actually, I am also getting same issue my plugin version is : nativescript-plugin-firebase": "^7.1.4"
@DeepikaKochar, as mentioned previously on this issue, the problem appears between 6.8.0 and 6.8.1. Reverting to 6.8.0 is what people have been doing for now.
@DeepikaKochar Well, can you share a repo then?
The problem with @sokolovstas's app was that there were plugin calls in app.ts/main.ts before the app was bootstrapped. Per the readme that's not supported; you should only require the plugin before the app is bootstrapped.
So I wonder if any of the other apps in this thread have the same cause.
That being said, I'm attempting to harden the plugin against this type of usage, which will be part of the 7.1.6 release. For now, I'm closing this issue.
@DeepikaKochar Well, can _you_ share a repo then?
@EddyVerbruggen ,
Here https://github.com/DeepikaKochar/demo-firebase-issue
@DeepikaKochar In your case, ngOnInit in AppComponent still runs before the app has started.
There are 3 options: either move the code out of AppComponent, or wrap it in a timeout, or (probably the best option) upgrade to 7.1.6 (will be released today).
Also, don't use init if you're not actually using Firebase features. You can rewrite it to this:
import { Component, OnInit } from "@angular/core";
import { messaging, Message } from "nativescript-plugin-firebase/messaging";
@Component({
moduleId: module.id,
selector: "ns-app",
templateUrl: "app.component.html"
})
export class AppComponent implements OnInit {
ngOnInit() {
messaging.registerForPushNotifications({
onPushTokenReceivedCallback: (token: string): void => {
console.log("Firebase plugin received a push token: " + token);
},
onMessageReceivedCallback: (message: Message) => {
console.log("Push message received: " + message.title);
},
// Whether you want this plugin to automatically display the notifications or just notify the callback. Currently used on iOS only. Default true.
showNotifications: true,
// Whether you want this plugin to always handle the notifications when the app is in foreground. Currently used on iOS only. Default false.
showNotificationsWhenInForeground: true
}).then(() => console.log("Registered for push"));
messaging.getCurrentPushToken().then(token => console.log(`Current push token: ${token}`));
}
}
@EddyVerbruggen Thank you for 7.1.6! Now it works ok even on init method
@sokolovstas Awesome, thanks for reporting back!
@EddyVerbruggen, I can also confirm 7.1.6 works with the init but I have switched to just using messaging as you recommend, thank you so much!
Extremely unrelated and feel free to ignore, but above you said:
ngOnInit in AppComponent still runs before the app has started.
I know this is out of scope, but do we (users of nativescript) have any control over that? We are seeing an issue with older iphones where it axes the startup because the package has loaded, but we are not "launching" the app fast enough after that, despite optimizing about as much as we think we can in our control. We are going down the route of basically loading a fake blank app then lazy-loading the rest in, but I was curious if you had any insight on controlling this.
@DeepikaKochar In your case,
ngOnInitinAppComponentstill runs before the app has started.There are 3 options: either move the code out of
AppComponent, or wrap it in a timeout, or (probably the best option) upgrade to 7.1.6 (will be released today).Also, don't use
initif you're not actually using Firebase features. You can rewrite it to this:import { Component, OnInit } from "@angular/core"; import { messaging, Message } from "nativescript-plugin-firebase/messaging"; @Component({ moduleId: module.id, selector: "ns-app", templateUrl: "app.component.html" }) export class AppComponent implements OnInit { ngOnInit() { messaging.registerForPushNotifications({ onPushTokenReceivedCallback: (token: string): void => { console.log("Firebase plugin received a push token: " + token); }, onMessageReceivedCallback: (message: Message) => { console.log("Push message received: " + message.title); }, // Whether you want this plugin to automatically display the notifications or just notify the callback. Currently used on iOS only. Default true. showNotifications: true, // Whether you want this plugin to always handle the notifications when the app is in foreground. Currently used on iOS only. Default false. showNotificationsWhenInForeground: true }).then(() => console.log("Registered for push")); messaging.getCurrentPushToken().then(token => console.log(`Current push token: ${token}`)); } }
@EddyVerbruggen I'm getting this error on Nativescript-Vue and I'm using timeouts
on mounted hook I have
setTimeout(()=>{ this.firebaseInit(); }, 3000);
then the method
`
firebaseInit(){
firebase.init()
.then(instance => {
messaging.registerForPushNotifications({
onPushTokenReceivedCallback: (token) => {
console.log("Firebase plugin received a push token: " + token);
},
onMessageReceivedCallback: (message) => {
console.log("Push message received: " + message.title);
},
// Whether you want this plugin to automatically display the notifications or just notify the callback. Currently used on iOS only. Default true.
showNotifications: true,
// Whether you want this plugin to always handle the notifications when the app is in foreground. Currently used on iOS only. Default false.
showNotificationsWhenInForeground: false
})
.then(() => console.log("Registered for push"))
.catch(error => console.log(`registerForPushNotifications error: ${error}`));
setTimeout(()=>{
messaging.getCurrentPushToken()
.then(token => {
this.registerFirebase(token);
}, e => console.log("Error: " + (e.message || e)));
}, 5000);
})
.catch(error => {
console.log(`firebase.init error: ${error}`);
console.log("Prepare get token..");
setTimeout(()=>{
console.log("Getting token..");
messaging.getCurrentPushToken()
.then(token => {
console.log("Token found: ", token);
this.registerFirebase(token);
})
.catch(e => {
console.log("Error getting token: " + (e.message || e));
});
}, 5000);
});
},
`
Most helpful comment
Please. Share. A. Repo.