I am trying to generate token from FCM by following this link. I am facing issue in messaging.service
. I couldn't implement angularFireMessaging.messaging
, its shrowing error in messaging keyword as
Property 'messaging' does not exist on type 'AngularFireMessaging'
Code
import { Injectable } from '@angular/core';
import { AngularFireMessaging } from '@angular/fire/messaging';
import { BehaviorSubject } from 'rxjs'
@Injectable()
export class MessagingService {
currentMessage = new BehaviorSubject(null);
constructor(private angularFireMessaging: AngularFireMessaging) {
this.angularFireMessaging.messaging.subscribe( //issue here in messaging
(_messaging) => {
_messaging.onMessage = _messaging.onMessage.bind(_messaging);
_messaging.onTokenRefresh = _messaging.onTokenRefresh.bind(_messaging);
}
)
}
requestPermission() {
this.angularFireMessaging.requestToken.subscribe(
(token) => {
console.log(token);
},
(err) => {
console.error('Unable to get permission to notify.', err);
}
);
}
receiveMessage() {
this.angularFireMessaging.messages.subscribe(
(payload) => {
console.log("new message received. ", payload);
this.currentMessage.next(payload);
})
}
}
Where I am going wrong please help me out
Starting March 22, 2020, the versions 81 and 82 of chrome disallow the creation of any new subscriptions using FCM sender IDs. However, the versions 78,79 and 80 of chrome will still allow the FCM Sender IDs that were used before September 2019. All the other FCM Sender IDs will be rejected.
For sending FCM notification payload you can use Firebase Cloud Messaging Tool in firebase console. And click on Send your first message. Then enter the Title and body field. If you wish to send it to a particular device then click on Send test message and enter the FCM registration token.
Firebase Cloud Messaging (FCM), formerly called Google Cloud Messaging (GCM), is a free cloud service from Google that allows app developers to send notifications and messages to users across a variety of platforms, including Android, iOS and web applications.
Send a test notification message Open the Notifications composer and select New notification. Enter the message text. Select Send test message. In the field labeled Add an FCM registration token, enter the registration token you obtained in a previous section of this guide.
I think going back to an older version is not an ideal solution. I think the author of this question followed a tutorial is a bit out of date.
For the latest version,
this.angularFireMessaging.messaging.subscribe( //issue here in messaging
(_messaging) => {
_messaging.onMessage = _messaging.onMessage.bind(_messaging);
_messaging.onTokenRefresh = _messaging.onTokenRefresh.bind(_messaging);
}
)
is not required
Remove everything in the constructor, and update your package.json with the latest version below (at the time of writing this answer)
"@angular/fire": "^6.0.0",
"firebase": "^7.15.1",
It will work just fine.
If you'd like to know more details, please follow this official tutorial https://github.com/angular/angularfire/blob/master/docs/messaging/messaging.md
Simply remove them. The error plainly told you that:
Property 'messaging' does not exist on type 'AngularFireMessaging'
From:
constructor(private angularFireMessaging: AngularFireMessaging) {
this.angularFireMessaging.messaging.subscribe( //issue here in messaging
(_messaging) => {
_messaging.onMessage = _messaging.onMessage.bind(_messaging);
_messaging.onTokenRefresh = _messaging.onTokenRefresh.bind(_messaging);
}
)
}
Into:
constructor(private angularFireMessaging: AngularFireMessaging) {}
Reference: https://github.com/angular/angularfire/blob/HEAD/docs/messaging/messaging.md
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With