FCM getToken () returns nothing

I am trying to use Firebase Cloud Messaging with Angular2, but it looks like they don’t want us to be @Google.

I followed this and this to be able to stop the errors.

Now I am faced with the following problem: Why does messaging.getToken() not return anything? There is no error, there is no token in the console, nothing.

Any help is more than welcome. Thanks.

EDIT I updated the code below when trying to use onTokenRefresh() . This does not change anything. I feel this is due to the fact that I am not actually connected to my firebase files. Has anyone been able to do FCM with Angular2 and AngularFire2?

 import {Component, OnInit, Inject} from '@angular/core'; import { FirebaseApp } from "angularfire2"; import * as firebase from 'firebase'; @Component({ templateUrl: './+config.component.html', styleUrls: ['./+config.component.scss'] }) export class UserConfigComponent implements OnInit { private _messaging: firebase.messaging.Messaging; constructor(@Inject(FirebaseApp) private _firebaseApp: firebase.app.App) { this._messaging = firebase.messaging(); } ngOnInit() { // Callback fired if Instance ID token is updated. this._messaging.onTokenRefresh(function() { this._messaging.getToken() .then(function(refreshedToken) { console.log('Token refreshed.', refreshedToken); }) .catch(function(err) { console.log('Unable to retrieve refreshed token ', err); }); }); } requestPushNotif() { this._messaging.requestPermission() .then(() => { console.log('have permission'); return this._messaging.getToken(); }) .then(function(token) { console.log(token); }) .catch((error) => { console.log(error); }); } } 
+2
angular firebase firebase-cloud-messaging angularfire2
source share
1 answer

Ok, I found a solution. The problem arose due to the relationship between Angular -CLI and AngularFire2.

It is here .

I had to add the following to src/tsconfig.json and to src/typings.d.ts :

 "types": [ "firebase" ] 

and

 declare var require: any; declare var module: any; 

I hope this can help someone.

Thank you Frank van Pufflen for your help. You are always here to help me with my bomb :)

EDIT I just found out that it does not work in all browsers. It works in firefox, but not in chrome ... How did it happen?

+3
source share

All Articles