问题描述
使用@angular/fire/messaging
在前台接收Firebase推送通知时.方法是:
When I am receiving firebase push notifications in the foreground, by using @angular/fire/messaging
. The method is:
this.angularFireMessaging.messages.subscribe(
(payload) => {
console.log("new message received. ", payload);
this.currentMessage.next(payload);
})
让我分享我的完整代码: PushNotificationsService代码我已编写.
Let me share my complete code: PushNotificationsService Code I have written.
我的Angular-cli版本:
Angular CLI: 8.1.3
Node: 12.4.0
OS: linux x64
Angular: 8.1.3
... animations, cli, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router
Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.801.3
@angular-devkit/build-angular 0.801.3
@angular-devkit/build-optimizer 0.801.3
@angular-devkit/build-webpack 0.801.3
@angular-devkit/core 8.1.3
@angular-devkit/schematics 8.1.3
@angular/fire 5.3.0
@ngtools/webpack 8.1.3
@schematics/angular 8.1.3
@schematics/update 0.801.3
rxjs 6.4.0
typescript 3.4.5
webpack 4.35.2
让我分享我的package.json文件: package.json
Let me share my package.json files: package.json
当我在前台收到消息时,出现以下错误:
Unhandled Promise rejection: this._next is not a function ; Zone: <root> ; Task: ServiceWorkerContainer.addEventListener:message ; Value: TypeError: "this._next is not a function"
next RxJS
messageEventListener index.esm.js:1046
step tslib.es6.js:99
verb tslib.es6.js:80
__awaiter tslib.es6.js:73
ZoneAwarePromise Angular
__awaiter tslib.es6.js:69
messageEventListener index.esm.js:1035
WindowController index.esm.js:876
Angular 5
next@http://localhost:4200/vendor.js:111323:18
./node_modules/@firebase/messaging/dist/index.esm.js/WindowController.prototype.messageEventListener/</<@http://localhost:4200/firebase-messaging.js:2418:34
step@http://localhost:4200/vendor.js:127272:23
verb/<@http://localhost:4200/vendor.js:127253:53
__awaiter/<@http://localhost:4200/vendor.js:127246:71
ZoneAwarePromise@http://localhost:4200/polyfills.js:3882:29
__awaiter@http://localhost:4200/vendor.js:127242:12
./node_modules/@firebase/messaging/dist/index.esm.js/WindowController.prototype.messageEventListener@http://localhost:4200/firebase-messaging.js:2407:71
WindowController/<@http://localhost:4200/firebase-messaging.js:2248:26
invokeTask@http://localhost:4200/polyfills.js:3397:31
runTask@http://localhost:4200/polyfills.js:3174:47
invokeTask@http://localhost:4200/polyfills.js:3471:34
invokeTask@http://localhost:4200/polyfills.js:4609:14
globalZoneAwareCallback@http://localhost:4200/polyfills.js:4635:27
任何帮助都是非常重要的! 代码:GITHUB REPO LINK
Any help is highly appreciable! CODE: GITHUB REPO LINK
我已经在GitHub代码中从firebase更新了我的密钥
I have update my secret key from firebase in the GitHub code
推荐答案
是的我意识到我使用了错误版本的"@ angular/fire":"^ 5.3.0",该版本与"firebase"不兼容:" ^ 7.6.2,位于我的package.json中.
Yes What I have realized that i had using the wrong version of "@angular/fire": "^5.3.0" which is not compatible with "firebase": "^7.6.2", in my package.json.
所以,我做了什么-
在firebase-messaging-sw.js或服务工作者文件中?
In firebase-messaging-sw.js or the service worker file?
importScripts('https://www.gstatic.com/firebasejs/5.0.0/firebase-app.js');importScripts('https://www.gstatic.com/firebasejs/5.0.0/firebase-messaging.js');
importScripts('https://www.gstatic.com/firebasejs/5.0.0/firebase-app.js');importScripts('https://www.gstatic.com/firebasejs/5.0.0/firebase-messaging.js');
应与package.json上的Firebase具有相同的版本
should have the same version with your firebase on package.json
"dependencies": {..."firebase": "^5.0.0","@angular/fire": "^5.0.0",...}
"dependencies": {..."firebase": "^5.0.0","@angular/fire": "^5.0.0",...}
它的工作就像一种魅力.
And it is working like a charm.
这篇关于未处理的承诺拒绝:this._next不是函数:@ angular/fire/messaging中的区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!