我试图让 Firebase 在 Vuzix Blade 上的 Unity 项目中运行,以便在那里接收推送通知。但是,OnTokenReceived
回调永远不会被调用,所以我没有得到任何令牌来处理推送通知。
Vuzix Blade 在 Android 5 上运行,我已经安装了 Google Play 服务和 Google Play 商店,因为默认情况下没有安装它们,但 Firebase 需要它们。Firebase 似乎可以正常启动,或者至少我在 logcat 上没有收到任何错误消息,并且CheckAndFixDependenciesAsync()
正确地以Firebase.DependencyStatus.Available
.
相同的 apk 在我的 Android 手机(OnePlus 5)上运行良好,在那里我获得了一个令牌,并且可以在应用程序运行时和后台接收通知。
我正在使用 Unity 2018.3 和 Firebase SDK 5.7.0(但结果与 5.6.0 相同)。
private void Awake()
{
Firebase.FirebaseApp.CheckAndFixDependenciesAsync().ContinueWith(
task =>
{
var dependencyStatus = task.Result;
if ( dependencyStatus == Firebase.DependencyStatus.Available ) // this is always true
{
// Create and hold a reference to your FirebaseApp,
// where app is a Firebase.FirebaseApp property of your application class.
m_kFirebaseApp = Firebase.FirebaseApp.DefaultInstance;
// Set a flag here to indicate whether Firebase is ready to use by your app.
Firebase.Messaging.FirebaseMessaging.TokenRegistrationOnInitEnabled = true;
Firebase.Messaging.FirebaseMessaging.TokenReceived += OnTokenReceived;
Firebase.Messaging.FirebaseMessaging.MessageReceived += OnMessageReceived;
}
else
{
Debug.LogError(string.Format("Could not resolve all Firebase dependencies: {0}", dependencyStatus ) );
// Firebase Unity SDK is not safe to use here.
}
} );
}
// This never gets called!
public void OnTokenReceived(object sender, Firebase.Messaging.TokenReceivedEventArgs token )
{
m_kToken = token.Token;
Debug.Log( "Received Registration Token: " + token.Token );
}