无法解析FCM的令牌,同时实现Xamarin的推送通知

wwtsj6pe  于 12个月前  发布在  其他
关注(0)|答案(2)|浏览(149)

我已经清楚地按照下面的链接实现推送通知,而点击注册从Android模拟器我得到下面的错误消息从类DeviceInstallationService:
https://learn.microsoft.com/en-us/azure/developer/mobile-apps/notification-hubs-backend-service-xamarin-forms
错误:无法解析FCM的令牌
我做的唯一的改变是使用FirebaseInstallations而不是FirebaseInstanceId,因为它说FirebaseInstanceId。

protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);

        Bootstrap.Begin(() => new DeviceInstallationService());

        Firebase.FirebaseApp.InitializeApp(Application.Context);

        if (DeviceInstallationService.NotificationsSupported)
        {
            FirebaseInstallations.GetInstance(Firebase.FirebaseApp.Instance).GetId();
            //FirebaseInstanceId.Instance. GetInstance(Firebase.FirebaseApp.Instance)
            //    .GetInstanceId()
            //    .AddOnSuccessListener(this);
        }

        Xamarin.Essentials.Platform.Init(this, savedInstanceState);
        global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
        LoadApplication(new App());

        ProcessNotificationActions(Intent);
    }

字符串
任何提示如何解决这个问题?

qyyhg6bp

qyyhg6bp1#

您需要使用FirebaseMessaging Class来获取token。可以使用以下代码生成token:

var token = FirebaseMessaging.Instance.GetToken();

字符串
关于Firebase InstanceId,官方文档是这样说的:
已弃用此类FirebaseInstanceId。Firebase示例ID已替换为应用示例标识符的FirebaseInstallations和FCM注册令牌的FirebaseMessaging.getToken()。

cxfofazt

cxfofazt2#

protected override void OnCreate(Bundle savedInstanceState)
{

FirebaseOptions baseOptions = FirebaseOptions.FromResource(Android.App.Application.Context);
FirebaseOptions options = new FirebaseOptions.Builder(baseOptions).SetProjectId(baseOptions.StorageBucket.Split('.')[0]).Build();
FirebaseApp.ClearInstancesForTest();
FirebaseApp app = FirebaseApp.InitializeApp(Android.App.Application.Context, options);
var refreshedToken = await FirebaseMessaging.Instance.GetToken();

}

字符串

相关问题