“成功回调ID:CCCometChat1199030706中的错误:TypeError:无法读取未定义的属性'fcm'”

时间:2019-01-28 08:18:57

标签: typescript ionic3 angular5 cordova-plugin-fcm cometchat

我在彗星聊天中使用相同的代码进行推送通知。打开彗星聊天窗口时,显示“成功回调ID:CCCometChat1199030706错误:TypeError:无法读取未定义的属性'fcm'”

我的代码在这里:

declare var CCCometChat: any; 


licenseKey = "COMETCHAT-UWUEP-JSKVT-UPXXN-H2Y7Z";
apiKey = "52131x665661ed305388bf2fce242889ee3774";

openCometChat() {

    var isFullScreen = true;
    CCCometChat.launchCometChat(isFullScreen, data => {
        console.log("launch come chat data", data);

        CCCometChat.getPlatform(currentplatform => {
            console.log("getPlatform", currentplatform);
            if (currentplatform.platform == "Android") {

                console.log("platform data", data);

                data = JSON.parse(data);
                console.log("json parse data", data);

                if (data.hasOwnProperty('userInfoCallback')) {
                    console.log("data.userInfoCallback", data.userInfoCallback);
                    console.log("data.userInfoCallback.push_channel", data.userInfoCallback.push_channel);
                    // this.checkFCM(data.userInfoCallback.push_channel);
                    this.fcm.subscribeToTopic(data.userInfoCallback.push_channel);
                    this.fcm.onNotification().subscribe(data => {
                        console.log("onNotification data", data);

                        this.notifyData = JSON.parse(data.data);
                        console.log('this.notifyData -> ' +JSON.stringify(this.notifyData));
                        this.message = this.notifyData.message.message;
                        console.log('this.message -> ' +JSON.stringify(this.message));

                        if(data.wasTapped){
                          console.log("Received in background");
                          console.log('background this.message -> ' +JSON.stringify(this.message));
                        } else {
                          console.log("Received in foreground");
                          let confirmAlert = this.alertCtrl.create({
                            title: 'New Notification',
                            message: this.message,
                            buttons: [{
                              text: 'Ignore',
                              role: 'cancel'
                            }, {
                              text: 'View',
                              handler: () => {
                                //TODO: Your logic here
                                console.log("ok clicked");

                              }
                            }]
                          });
                          confirmAlert.present();
                        }

                        // if (data.wasTapped) {
                        //     console.log("Received in background" + JSON.stringify(data));

                        // } else {
                        //     console.log("Received in foreground" + JSON.stringify(data));
                        // };

                    });
                } else if (data.hasOwnProperty('chatroomInfoCallback')) {

                    console.log("data.chatroomInfoCallback", data.chatroomInfoCallback);
                    console.log("data.chatroomInfoCallback.push_channel", data.chatroomInfoCallback.push_channel);

                    if (data.chatroomInfoCallback.hasOwnProperty('action') && data.chatroomInfoCallback.action != "" && data.chatroomInfoCallback.action == "join") {
                      // this.checkFCM(data.chatroomInfoCallback.push_channel);
                        this.fcm.subscribeToTopic(data.chatroomInfoCallback.push_channel);
                        this.fcm.onNotification().subscribe(data => {
                            console.log("onNotification data", data);

                            if (data.wasTapped) {
                                console.log("Received in background" + JSON.stringify(data));

                            } else {
                                console.log("Received in foreground" + JSON.stringify(data));
                            };

                        });
                    }

                }

            } else {
                data = JSON.stringify(data);
                data = JSON.parse(data);
                if (data.hasOwnProperty('userInfoCallback')) {
                    this.fcm.subscribeToTopic(data.userInfoCallback.push_channel);
                    this.fcm.onNotification().subscribe(data => {
                        if (data.wasTapped) {
                            console.log("Received in background" + JSON.stringify(data));

                        } else {
                            console.log("Received in foreground" + JSON.stringify(data));
                        };

                    });
                } else if (data.hasOwnProperty('chatroomInfoCallback')) {

                    if (data.chatroomInfoCallback.hasOwnProperty('action') && data.chatroomInfoCallback.action != "" && data.chatroomInfoCallback.action == "join") {
                        this.fcm.subscribeToTopic(data.chatroomInfoCallback.push_channel);
                        this.fcm.onNotification().subscribe(data => {
                            if (data.wasTapped) {
                                console.log("Received in background" + JSON.stringify(data));

                            } else {
                                console.log("Received in foreground" + JSON.stringify(data));
                            };

                        });
                    }

                }


            }

        });

    }, data => {

    });
}

如何解决上述“ fcm”未定义错误?请尽快在这里给您答复,我们将不胜感激。

1 个答案:

答案 0 :(得分:0)

请从以下链接下载FCM插件: https://temp.cometchat.com/cordova-plugin-fcm.zip

完成后,将此文件夹替换为项目目录中的FCM插件文件夹。 如果需要进一步的帮助,请随时与我们联系。

P.S:此帐户归CometChat团队所有。