How to generate FCM token in ionic 1??I don’t know nothing about it
for getting firebase token do this
if (window.FirebasePlugin) {
var Token
// window.FirebasePlugin.grantPermission(); //in ios
window.FirebasePlugin.getToken(function (token) {
Token = token;
console.log(token);
}, function (error) {
});
window.FirebasePlugin.onTokenRefresh(function (token) {
Token = token;
console.log(token);
}, function (error) {
});
}
hopping that
1)Your created android project in firebase console ( and downloaded google-services.json file)
2) using firebase pluggin etc
New Project will be create in firebase console or existing???
and tell me firebase plugin
and whare I use this code
and project which will be create in firebase console it is only android???If yes then what about iOS platform
“cordova-plugin-firebase” this is the plugin that you need to install .
https://firebase.google.com/docs/android/setup
in firebase you need to create separate apps for both ios and android
you can use above code in a controller or a service .
if you want to send notifications to a specific user then you need to keep this firebase token in backend or api
if you are going to send broadcast messages then no need to keep this tokens
Hey I followed steps what you suggested me…Thanks for it but when I keep your code in my code that time it is not working…check my code it is right or wrong
$ionicPlatform.ready(function () {
$scope.$apply(function () {
if (window.FirebasePlugin) {
var Token
window.FirebasePlugin.grantPermission(); //in ios
window.FirebasePlugin.getToken(function (token) {
Token = token;
console.log(token);
}, function (error) {
});
window.FirebasePlugin.onTokenRefresh(function (token) {
Token = token;
console.log(token);
}, function (error) {
});
alert(token);
}
}
Let me know what was the error?
No error is occurring but I can’t alert my FCM
there is no log message also right? one more thing are you checking in ripple? this code not works with ripple check with a device
ohkk…thank you for help…but I solved it by this
in which file i should add the gettoken(), onrefresh() ?
for ionic 1 on file app.js