gpt4 book ai didi

ios - 使用 Firebase/Google Cloud Functions 推送通知

转载 作者:行者123 更新时间:2023-11-29 00:04:28 25 4
gpt4 key购买 nike

我正尝试在将数字写入_random 时发送通知。我能够获得设备 token ,并且云功能完美运行。但是,我没有在模拟器上收到通知。我正在使用推送到 Firebase 的通知 token 进行测试。如果有人可以提供帮助,我们将不胜感激。

/image/OB94c.png

const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);

//Initial function call:
exports.makeRandomFigures = functions.https.onRequest((req, res) => {
    //create database ref
    var rootRef = admin.database().ref();
    var doc_count_temp = 0;
    var keys = [];
    var random_num = 0;

    //get document count
    rootRef.once('value', (snapshot) => {
        doc_count_temp = snapshot.numChildren();
        //real number of member. if delete _timeStamp then minus 2 not 3!
        var doc_count = doc_count_temp - 3;

        //get num array previous generated
        var xRef = rootRef.child("_usedFigures");

        xRef.once('value', function(snap) {
            snap.forEach(function(item) {
                var itemVal = item.val();
                keys.push(itemVal);
            });
            //get non-duplicated random number
            var is_equal = true;
            while (is_equal) {
                random_num = Math.floor((Math.random() * doc_count) + 1);
                is_equal = keys.includes(random_num);
            }

            //insert new random vaule to _usedFigures collection
            rootRef.child('_usedFigures').push(random_num);
            rootRef.child('_random').set(random_num);
        });
    });

    //send back response
    res.redirect(200);
});

exports.sendFigureNotification = functions.database.ref('_random').onWrite(event => {

const payload = {
notification: {
title: 'Title',
body: `Test`, //use _random to get figure at index key
badge: '1',
sound: 'default'
}
};

const options = {
priority: "high",
timeToLive: 60 * 60 * 24, //24 hours
content_available: true
};
const token = "cge0F9rUTLo:APA91bGNF3xXI-5uxrdj8BYqRPkxUPA5x9IQALtm3VEFJAdV2WQrQufNkzIclT5B671mBcvR6IDMbgSKyL7iG2jAuxRM3qR3MXhkNp1_utlXhCpE2VZqTw6Yw3d4iMMvHl1B-Cvik6NY";
console.log('Sending notifications');
return admin.messaging().sendToDevice(token, payload, options);


});

最佳答案

您无法在模拟器上获得推送通知。

要尝试一些替代方法,请检查此链接:

How can I test Apple Push Notification Service without an iPhone?

关于ios - 使用 Firebase/Google Cloud Functions 推送通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48513361/

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