我正在尝试在IOS上实现FCM的缓存机制。我正在使用 Xamarin Forms 和 CrossGeeks FirebasePushNotificationPlugin
推送通知服务运行良好。我使用的有效负载模式如下
{
"data": {
"message" : "my_custom_value",
"other_key" : true,
"body":"test"
},
"notification": {
"body" : "hello",
"title": "firebase",
"sound": "default",
"content_available" : true
},
"priority": "high",
"condition": "'general' in topics"
}
以上模式在 IOS 主屏幕上显示已发送的通知作为警报。
我编写了一个依赖服务,用于在应用程序启动时获取未删除或未打开的累积通知。依赖服务包括以下代码
await UNUserNotificationCenter.Current.GetDeliveredNotificationsAsync();
当我使用上述有效负载时,我可以获得累积的通知。但是当我使用如下所示的有效负载模式时,我不能。
{
"data": {
"message" : "my_custom_value",
"other_key" : true,
"body":"test"
},
"notification": {
"content_available" : true
},
"priority": "high",
"condition": "'general' in topics"
}
实际上,我想为我的缓存机制的每个通知发送 2 个有效负载类型,因为会阻止用户的删除操作。之后,我想在我的应用程序的通知页面中显示缓存的通知,而不会丢失任何通知。
我的问题是“我没有从
UNUserNotificationCenter
获得静默有效负载值,这种方法是否可行?”
或者我可以在我的应用程序终止时阻止用户从 IOS 主屏幕执行通知删除操作吗?
注意: info.plist 中我的最低操作系统版本是 10.0
提前谢谢您。
我知道这已经过时了,但这是 2024 年的更新。从我的 api 来看,这里是我正在创建、添加到列表并使用 FirebaseAdmin.Messaging 发送该列表的消息示例。 iOS 现在需要 APNS,因为 2020 年似乎不需要。而且我正在使用 MAUI。
有用的链接 https://firebase.google.com/docs/reference/admin/dotnet/class/firebase-admin/messaging/aps
// In my case I loop through a list
var messageList = new List<FirebaseAdmin.Messaging.Message>();
foreach (whatever...)
{
var message = new FirebaseAdmin.Messaging.Message()
{
Token = firebaseToken,
Notification = new Notification
{
Title = "New Message!",
Body = "Message Here..."
},
Data = new Dictionary<string, string>()
{
// Custom dictionary (works for both iOS and Android)
},
Apns = new ApnsConfig()
{
Aps = new Aps
{
ContentAvailable = true, // For awaking app to run snippet
// Badge = trackingUserNotifications_InMyCase
// Wish you could increment the badge but AFAIK you can't
}
}
}
MessageList.Add(message)
}
// then send them all
await FirebaseMessaging.DefaultInstance.SendAllAsync(messageList);