我已经为Unity实施了Firebase消息传递SDK(仅限Android atm)。 我已经能够毫无问题地收到推送通知。
我遇到的问题是消息中的数据是空的。 这是我的C#代码:
void Start()
{
FirebaseMessaging.TokenReceived += FirebaseMessaging_TokenReceived;
FirebaseMessaging.MessageReceived += FirebaseMessaging_MessageReceived;
}
private void FirebaseMessaging_TokenReceived(object sender, TokenReceivedEventArgs args)
{
Debug.Log("FirebasePushNotification - Received Registration Token: " + args.Token);
}
private void FirebaseMessaging_MessageReceived(object sender, MessageReceivedEventArgs args)
{
Debug.Log("FirebasePushNotification - Received a new message!");
Debug.Log(GetFirebaseMessageString(args.Message));
}
/// <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: ", msg.MessageId));
builder.AppendLine(string.Format("Message Type: ", msg.MessageType));
builder.AppendLine(string.Format("Priority: ", msg.Priority));
builder.AppendLine(string.Format("From: ", msg.From));
builder.AppendLine(string.Format("To: ", msg.To));
builder.AppendLine(string.Format("Collapse Key: ", msg.CollapseKey));
builder.AppendLine(string.Format("Error: ", msg.Error));
builder.AppendLine(string.Format("Error Description: ", msg.ErrorDescription));
builder.AppendLine(string.Format("Time To Live: ", msg.TimeToLive));
builder.AppendLine(string.Format("Raw Data: ", msg.RawData));
builder.AppendLine(string.Format("Notification Opened: ", msg.NotificationOpened));
if (msg.Notification != null)
{
builder.AppendLine(string.Format(".Notification Title: ", msg.Notification.Title));
builder.AppendLine(string.Format(".Notification Tag: ", msg.Notification.Tag));
builder.AppendLine(string.Format(".Notification Body: ", msg.Notification.Body));
builder.AppendLine(string.Format(".Notification ClickAction: ", msg.Notification.ClickAction));
builder.AppendLine(string.Format(".Notification Sound: ", msg.Notification.Sound));
}
builder.AppendLine("############# End #############");
return builder.ToString();
}
#### Firebase Message ####下的所有参数均为空。 有任何想法吗? 谢谢!
答案 0 :(得分:0)
问题似乎是由于C#代码。
String.Format需要一个带有应该插入字符串的索引参数的大括号(索引从0开始)。在您的代码中:
spark.sparkContext.newAPIHadoopFile(file_path,'com.test.multi.reader.CustomFileFormat','org.apache.hadoop.io.LongWritable','org.apache.hadoop.io.Text',conf=conf)
形成有关String.Format的更多信息,请查看https://msdn.microsoft.com/it-it/library/system.string.format(v=vs.110).aspx
所以固定代码将是:
string.Format("Message Id: {0}", msg.MessageId)
从Firebase控制台测试它。