C# Unity中的Firebase消息传递-获取空消息

C# Unity中的Firebase消息传递-获取空消息,c#,android,firebase,unity3d,firebase-cloud-messaging,C#,Android,Firebase,Unity3d,Firebase Cloud Messaging,我已经为Unity实现了Firebase消息SDK(仅适用于Android atm)。 我能够毫无问题地收到推送通知 我的问题是,消息中的数据是空的。 这是我的C#代码: void Start() { FirebaseMessaging.TokenReceived+=FirebaseMessaging_TokenReceived; FirebaseMessaging.MessageReceived+=FirebaseMessaging_MessageReceived; } private voi

我已经为Unity实现了Firebase消息SDK(仅适用于Android atm)。 我能够毫无问题地收到推送通知

我的问题是,消息中的数据是空的。 这是我的C#代码:

void Start()
{
FirebaseMessaging.TokenReceived+=FirebaseMessaging_TokenReceived;
FirebaseMessaging.MessageReceived+=FirebaseMessaging_MessageReceived;
}
private void FirebaseMessaging_TokenReceived(对象发送方,TokenReceivedEventArgs args)
{
Log(“FirebasePushNotification-收到的注册令牌:“+args.Token”);
}
private void FirebaseMessaging_MessageReceived(对象发送方,MessageReceivedEventArgs参数)
{
Log(“FirebasePushNotification-收到新消息!”);
Log(GetFirebaseMessageString(args.Message));
}
/// 
///用于调试
/// 
/// 
/// 
私有字符串GetFireBaseMessage字符串(FirebaseMessage消息)
{
var builder=新的StringBuilder();
建筑商。附加物(“火基信息”);
AppendLine(string.Format(“MessageId:”,msg.MessageId));
AppendLine(string.Format(“消息类型:”,msg.MessageType));
AppendLine(string.Format(“Priority:”,msg.Priority));
AppendLine(string.Format(“From:”,msg.From));
AppendLine(string.Format(“To:”,msg.To));
AppendLine(string.Format(“折叠键:”,msg.CollapseKey));
AppendLine(string.Format(“Error:,msg.Error”);
AppendLine(string.Format(“错误描述:”,msg.ErrorDescription));
AppendLine(string.Format(“生存时间:”,msg.TimeToLive));
AppendLine(string.Format(“原始数据:”,msg.RawData));
AppendLine(string.Format(“通知打开:”,msg.NotificationOpened));
如果(msg.Notification!=null)
{
AppendLine(string.Format(“.Notification Title:”,msg.Notification.Title));
AppendLine(string.Format(“.Notification标记:”,msg.Notification.Tag));
AppendLine(string.Format(“.Notification Body:”,msg.Notification.Body));
AppendLine(string.Format(“.Notification-ClickAction:”,msg.Notification.ClickAction));
AppendLine(string.Format(“.Notification-Sound:”,msg.Notification.Sound));
}
建筑商。附加物(“#################################”;
返回builder.ToString();
}
#############下的所有参数均为空。 有什么想法吗? 谢谢

这个问题似乎是由C代码引起的

Format需要一个大括号,括号中的参数索引应插入字符串(索引从0开始)。在代码中:

string.Format("Message Id: {0}", msg.MessageId)
有关字符串的更多信息。格式查看

因此,固定代码为:

/// <summary>
/// Used for debug
/// </summary>
/// <param name="msg"></param>
/// <returns></returns>
private string GetFirebaseMessageString(FirebaseMessage msg)
{
    var builder = new StringBuilder();

    builder.AppendLine("############# Firebase Message #############");
    builder.AppendLine(string.Format("Message Id: {0}", msg.MessageId));
    builder.AppendLine(string.Format("Message Type: {0}", msg.MessageType));
    builder.AppendLine(string.Format("Priority: {0}", msg.Priority));
    builder.AppendLine(string.Format("From: {0}", msg.From));
    builder.AppendLine(string.Format("To: {0}", msg.To));
    builder.AppendLine(string.Format("Collapse Key: {0}", msg.CollapseKey));
    builder.AppendLine(string.Format("Error: {0}", msg.Error));
    builder.AppendLine(string.Format("Error Description: {0}", msg.ErrorDescription));
    builder.AppendLine(string.Format("Time To Live: {0}", msg.TimeToLive));
    builder.AppendLine(string.Format("Raw Data: {0}", msg.RawData));
    builder.AppendLine(string.Format("Notification Opened: {0}", msg.NotificationOpened));
    if (msg.Notification != null)
    {
        builder.AppendLine(string.Format(".Notification Title: {0}", msg.Notification.Title));
        builder.AppendLine(string.Format(".Notification Tag: {0}", msg.Notification.Tag));
        builder.AppendLine(string.Format(".Notification Body: {0}", msg.Notification.Body));
        builder.AppendLine(string.Format(".Notification ClickAction: {0}", msg.Notification.ClickAction));
        builder.AppendLine(string.Format(".Notification Sound: {0}", msg.Notification.Sound));
    }
    builder.AppendLine("############# End #############");

    return builder.ToString();
}
//
///用于调试
/// 
/// 
/// 
私有字符串GetFireBaseMessage字符串(FirebaseMessage消息)
{
var builder=新的StringBuilder();
建筑商。附加物(“火基信息”);
AppendLine(string.Format(“MessageId:{0}”,msg.MessageId));
AppendLine(string.Format(“消息类型:{0}”,msg.MessageType));
AppendLine(string.Format(“Priority:{0}”,msg.Priority));
AppendLine(string.Format(“From:{0}”,msg.From));
AppendLine(string.Format(“To:{0}”,msg.To));
AppendLine(string.Format(“折叠键:{0}”,msg.CollapseKey));
AppendLine(string.Format(“Error:{0}”,msg.Error));
AppendLine(string.Format(“错误描述:{0}”,msg.ErrorDescription));
AppendLine(string.Format(“生存时间:{0}”,msg.TimeToLive));
AppendLine(string.Format(“原始数据:{0}”,msg.RawData));
AppendLine(string.Format(“通知打开:{0}”,msg.NotificationOpened));
如果(msg.Notification!=null)
{
AppendLine(string.Format(“.Notification Title:{0}”,msg.Notification.Title));
AppendLine(string.Format(“.Notification标记:{0}”,msg.Notification.Tag));
AppendLine(string.Format(“.Notification Body:{0}”,msg.Notification.Body));
AppendLine(string.Format(“.Notification-ClickAction:{0}”,msg.Notification.ClickAction));
AppendLine(string.Format(“.Notification-Sound:{0}”,msg.Notification.Sound));
}
建筑商。附加物(“#################################”;
返回builder.ToString();
}
从Firebase控制台进行测试是可行的。

问题似乎是由C代码引起的

Format需要一个大括号,括号中的参数索引应插入字符串(索引从0开始)。在代码中:

string.Format("Message Id: {0}", msg.MessageId)
有关字符串的更多信息。格式查看

因此,固定代码为:

/// <summary>
/// Used for debug
/// </summary>
/// <param name="msg"></param>
/// <returns></returns>
private string GetFirebaseMessageString(FirebaseMessage msg)
{
    var builder = new StringBuilder();

    builder.AppendLine("############# Firebase Message #############");
    builder.AppendLine(string.Format("Message Id: {0}", msg.MessageId));
    builder.AppendLine(string.Format("Message Type: {0}", msg.MessageType));
    builder.AppendLine(string.Format("Priority: {0}", msg.Priority));
    builder.AppendLine(string.Format("From: {0}", msg.From));
    builder.AppendLine(string.Format("To: {0}", msg.To));
    builder.AppendLine(string.Format("Collapse Key: {0}", msg.CollapseKey));
    builder.AppendLine(string.Format("Error: {0}", msg.Error));
    builder.AppendLine(string.Format("Error Description: {0}", msg.ErrorDescription));
    builder.AppendLine(string.Format("Time To Live: {0}", msg.TimeToLive));
    builder.AppendLine(string.Format("Raw Data: {0}", msg.RawData));
    builder.AppendLine(string.Format("Notification Opened: {0}", msg.NotificationOpened));
    if (msg.Notification != null)
    {
        builder.AppendLine(string.Format(".Notification Title: {0}", msg.Notification.Title));
        builder.AppendLine(string.Format(".Notification Tag: {0}", msg.Notification.Tag));
        builder.AppendLine(string.Format(".Notification Body: {0}", msg.Notification.Body));
        builder.AppendLine(string.Format(".Notification ClickAction: {0}", msg.Notification.ClickAction));
        builder.AppendLine(string.Format(".Notification Sound: {0}", msg.Notification.Sound));
    }
    builder.AppendLine("############# End #############");

    return builder.ToString();
}
//
///用于调试
/// 
/// 
/// 
私有字符串GetFireBaseMessage字符串(FirebaseMessage消息)
{
var builder=新的StringBuilder();
建筑商。附加物(“火基信息”);
AppendLine(string.Format(“MessageId:{0}”,msg.MessageId));
AppendLine(string.Format(“消息类型:{0}”,msg.MessageType));
AppendLine(string.Format(“Priority:{0}”,msg.Priority));
AppendLine(string.Format(“From:{0}”,msg.From));
AppendLine(string.Format(“To:{0}”,msg.To));
AppendLine(string.Format(“折叠键:{0}”,msg.CollapseKey));
AppendLine(string.Format(“Error:{0}”,msg.Error));
AppendLine(string.Format(“错误描述:{0}”,msg.ErrorDescription));
AppendLine(string.Format(“生存时间:{0}”,msg.TimeToLive));
AppendLine(string.Format(“原始数据:{0}”,msg.RawData));
AppendLine(string.Format(“通知打开:{0}”,msg.NotificationOpened));
如果(msg.Notification!=null)
{
AppendLine(string.Format(“.Notification Title:{0}”,msg.Notification.Title));
builder.AppendLine(string.Format(“.Notification标记