第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

未收到 Firebase 功能的通知

未收到 Firebase 功能的通知

藍山帝景 2021-08-06 10:11:24
我一直在嘗試Cloud Messaging為我的應用程序實施,以便應用程序的每個用戶在添加新孩子時都會自動收到通知Realtime Database.在我的文章中,MainActivity我使用此方法為每個用戶訂閱一個主題。FirebaseMessaging.getInstance().subscribeToTopic("latest_events").addOnSuccessListener(new OnSuccessListener<Void>() {            @Override            public void onSuccess(Void aVoid) {               // Toast.makeText(MainActivity.this, "Successfully subscribed", Toast.LENGTH_SHORT).show();            }        });我還firebase functions為我的后端安裝并部署了我的 javascript 代碼。索引.jsvar functions = require('firebase-functions');const admin = require('firebase-admin');admin.initializeApp(functions.config().firebase);exports.sendNotification = functions.database.ref("/Users").onWrite(event => {    var payload = {        notification: {            title: "A new user has been added!",            body: "Click to see"        }    };    if (event.data.previous.exists()) {        if (event.data.previous.numChildren() < event.data.numChildren()) {            return admin.messaging().sendToTopic("latest_events", payload);        } else {            return;        }    }    if (!event.data.exists()) {        return;    }    return admin.messaging().sendToTopic("latest_events", payload);});添加用戶時,我沒有收到所需的通知。似乎無法理解我做錯了什么。Firebase 函數(shù)日志 CatsendNotificationTypeError: Cannot read property 'previous' of undefined at exports.sendNotification.functions.database.ref.onWrite.event (/user_code/index.js:15:19) at cloudFunctionNewSignature (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:105:23) at cloudFunction (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:135:20) at /var/tmp/worker/worker.js:730:24 at process._tickDomainCallback (internal/process/next_tick.js:135:7)
查看完整描述

1 回答

?
長風秋雁

TA貢獻1757條經(jīng)驗 獲得超7個贊

您使用的是 Cloud Functions for Firebase 測試版中的語法。由于它已更新到 1.0,因此語法發(fā)生了變化,您需要更新代碼以匹配升級文檔中所述。


將其應用于您的代碼會導致如下結果:


var functions = require('firebase-functions');

const admin = require('firebase-admin');

admin.initializeApp();


exports.sendNotification = functions.database.ref("/Users").onWrite((change, context) => {


    var payload = {

        notification: {

            title: "A new user has been added!",

            body: "Click to see"


        }

    };


    if (change.before.exists()) {

        if (change.before.numChildren() < change.after.numChildren()) {

            return admin.messaging().sendToTopic("latest_events", payload);

        } else {

            return;

        }

    }


    if (!change.after.exists()) {

        return;

    }


    return admin.messaging().sendToTopic("latest_events", payload);


});

變化是:


有兩個參數(shù)傳遞到函數(shù)中,而以前只有一個。

您不再需要將配置傳遞到initializeApp.

在before和after快照現(xiàn)在可從change。


查看完整回答
反對 回復 2021-08-06
  • 1 回答
  • 0 關注
  • 171 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號