c#中FirebaseAdmin发送的FCM通知无法接收



我试图发送FCM通知到一个特定的设备后,一些数据保存到数据库。但是,我的手机应用程序在Android模拟器中运行,并使用Flutter构建,无法接收通知。

我从FCM控制台测试了相同的注册令牌,可以收到通知。

这是我在c#中实现的

using FirebaseAdmin.Messaging;
using Google.Apis.Auth.OAuth2;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
namespace MyNeighbours.Server.Infrastructure.Services
{
public class FirebaseService : IFirebaseService
{
public FirebaseService()
{
FirebaseApp.Create(new AppOptions()
{
Credential = GoogleCredential.FromFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "firebase-private-key.json")),
});
}
public async Task<string> SendNotification(IEnumerable<string> fcmRegistrationTokens, string title, string body)
{
Message message = new Message()
{
Token = "some valid token",
Data = new Dictionary<string, string>()
{
{"title", title},
{"body", body},
},
};
var response = await FirebaseMessaging.DefaultInstance.SendAsync(message);
return response;
}
}
}

每次当我发送通知时,响应总是显示成功并带有消息id。我还可以确认私钥json文件被加载。

有人能帮忙吗?谢谢你

尝试在Message{}中添加通知并设置声音和优先级:

Notification = new Notification()
{
Title = Title,
Body = Body
},
Android = new AndroidConfig()
{
Notification = new AndroidNotification()
{
Sound = "default",
Priority = NotificationPriority.MAX
}
},
Apns = new ApnsConfig()
{
Aps = new Aps()
{
Sound = "default"
}
}

最新更新