在3月9日左右,我收到了推送和静音通知,但在3月22日左右,我不再收到令牌和静音通知。当我创建一个新项目并实施FCM时,我仍然没有收到推送或静音通知,尽管我可以获得令牌。
是否有其他人经历过相同的症状并解决了该问题?
版本iPad 15.4.1Xamarin.Firebase.iOS.CloudMessaging 8.10.0
4.7.1中的库接收推送通知,而不是静音通知;更新到8.10.0后,推送和静音通知将不再被接收。
public override void ReceivedRemoteNotification(UIApplication application, NSDictionary userInfo)
{
Console.WriteLine(userInfo);
}
public override void DidReceiveRemoteNotification(UIApplication application, NSDictionary userInfo, Action<UIBackgroundFetchResult> completionHandler)
{
Console.WriteLine(userInfo);
}
public void WillPresentNotification(UNUserNotificationCenter center, UNNotification notification, Action<UNNotificationPresentationOptions> completionHandler)
{
Console.WriteLine(userInfo);
}
欢迎任何建议。致以最亲切的问候。
查看本文档,
send(message, dryRun)表示Sends the given message via FCM
。
sendToTopic(topic, payload, options)表示Sends an FCM message to a topic
.参见发送到主题的代码示例和详细文档。
在Functions中注册的Javascript是错误的。
坏代码:
const functions = require("firebase-functions");
const admin = require("firebase-admin");
admin.initializeApp(functions.config().firebase);
exports.BucketChanged=functions.region("asia-northeast1").storage.object()
.onFinalize(async (object)=>{
const topic = "TopicName";
const message = {
topic: topic,
data: {
body: object.name,
contentAvailable: "true",
},
};
admin.messaging().send(message)
.then((response) => {
console.log("Successfully sent message:", response);
})
.catch((error) => {
console.log("Error sending message", error);
});
}
);
好的代码:
"use strict";
const functions = require("firebase-functions");
const admin = require("firebase-admin");
admin.initializeApp(functions.config().firebase);
exports.sendSilentNotificationWithTopic = functions.region("asia-northeast1")
.region("asia-northeast1").storage.object().onFinalize(async (object) => {
const topic = "TopicName";
const payload = {
data: {
imageName: object.name,
},
};
const options = {
contentAvailable: true,
};
return admin.messaging().sendToTopic(topic, payload, options)
.then(function(response) {
return console.log("Successfully sent message:", response);
})
.catch(function(error) {
return console.log("Error sending message:", error);
});
});
主要是send和sendToTopic之间的区别,但是有人能解释为什么会发生这种情况吗?至少我现在做对了....