gpt4 book ai didi

angular - FCM消息问题

转载 作者:行者123 更新时间:2023-12-03 14:00:13 26 4
gpt4 key购买 nike

我正在尝试通过遵循此link从FCM生成 token 。我在messaging.service中遇到问题。我无法实现angularFireMessaging.messaging,它在messageing关键字中的拖延错误为

Property 'messaging' does not exist on type 'AngularFireMessaging'



代码
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);
})
}
}

我要去哪里错了,请帮帮我

最佳答案

我认为回到较旧的版本不是理想的解决方案。
我认为这个问题的作者在跟随教程之后有些过时了。

对于最新版本,

 this.angularFireMessaging.messaging.subscribe(  //issue here in messaging
(_messaging) => {
_messaging.onMessage = _messaging.onMessage.bind(_messaging);
_messaging.onTokenRefresh = _messaging.onTokenRefresh.bind(_messaging);
}
)

不需要

删除构造函数中的所有内容,并使用以下最新版本更新您的package.json(在编写此答案时)
"@angular/fire": "^6.0.0",
"firebase": "^7.15.1",

它将正常工作。

如果您想了解更多详细信息,请按照此官方教程 https://github.com/angular/angularfire/blob/master/docs/messaging/messaging.md进行操作。

关于angular - FCM消息问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61244212/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com