I've implemented the Firebase messaging SDK for Unity (only Android atm). I've been able to receive the push notification with no problem.
The problem I do have, is that the data inside the message is empty. Here is my C# code:
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();
}
All the parameters under #### Firebase Message #### are empty. Any ideas? Thanks!