Firebase OnTokenReceived不会在Unity中被触发

时间:2017-03-19 18:17:32

标签: c# unity3d firebase firebase-cloud-messaging

我需要在团结游戏中为推送通知设置FCM。为此,我使用Firebase文档中提到的初始化代码:

public void Start() {
  Firebase.Messaging.FirebaseMessaging.TokenReceived += OnTokenReceived;
  Firebase.Messaging.FirebaseMessaging.MessageReceived += OnMessageReceived;
}

public void OnTokenReceived(object sender, Firebase.Messaging.TokenReceivedEventArgs token) {
  UnityEngine.Debug.Log("Received Registration Token: " + token.Token);
}

public void OnMessageReceived(object sender, Firebase.Messaging.MessageReceivedEventArgs e) {
  UnityEngine.Debug.Log("Received a new message from: " + e.Message.From);
} 

该游戏使用GameSparks进行后端服务。我想在排行榜中通知用户新的高分。为此,我必须注册设备以进行推送通知,并根据GameSparks的文档,以下代码用于注册推送:

  new PushRegistrationRequest()
        .SetDeviceOS(deviceOS)
        .SetPushId(pushId)
        .Send((response) => {
        string registrationId = response.RegistrationId; 
        GSData scriptData = response.ScriptData; 
        });

取自pushId的是从FirebaseInstanceID.getToken()调用返回的注册ID here。我在这里做错了吗?如果有更好的解决方案,请告诉我。提前谢谢。

1 个答案:

答案 0 :(得分:0)

如果您没有在Android设备上构建和运行Unity项目,则不会收到令牌。如果您在设备上运行并连接到计算机,则可以使用以下方法检查是否触发了日志消息:

adb logcat -s Unity