3 月 9 日左右,我同時收到推送和靜默通知,但在 3 月 22 日左右,我停止接收令牌和靜默通知。當我創建一個新專案并實施 FCM 時,我仍然沒有收到推送或靜默通知,盡管我可以獲得令牌。
有沒有其他人遇到過同樣的癥狀并解決了問題?
版本 iPad 15.4.1 Xamarin.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);
}
歡迎任何建議。最好的祝福。
uj5u.com熱心網友回復:
請參閱此檔案,
send(message, dryRun) 的意思是Sends the given message via FCM。
sendToTopic(topic, payload, options) 表示。請Sends an FCM message to a topic參閱發送到主題以獲取代碼示例和詳細檔案。
uj5u.com熱心網友回復:
使用 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 之間的區別,但誰能解釋為什么會這樣?至少我現在做對了......
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/470500.html
標籤:C# IOS 火力基地 xamarin firebase-云消息传递
