如何将 Xamarin Forms [Android] 上的 Azure 通知中心注册更新为 FCMv1

问题描述 投票:0回答:1

我有一个 Xamarin Forms 应用程序(Android 应用程序),我知道我必须迁移到 FCMv1 协议才能向设备发送通知,我已阅读 Microsoft 的这篇关于迁移的文章,但我不清楚如何告诉我的 xamarin android 应用程序将自身注册为 FCMv1 注册。我现在的代码如下所示:

[Service(Exported = true)]
[IntentFilter(new[] { "com.google.firebase.MESSAGING_EVENT" })]
public class MyFirebaseMessagingService : FirebaseMessagingService
{
const string TAG = "MyFirebaseMessagingService";
NotificationHub hub;

public override void OnNewToken(string p0)
{
    base.OnNewToken(p0);
    SendRegistrationToServer(p0);
}

private void SendRegistrationToServer(string token)
{
    // Register with Notification Hubs
    hub = new NotificationHub(Helpers.ApiKeys.NotificationHubName, Helpers.ApiKeys.ListenConnectionString, this);
    try
    {
        hub.UnregisterAll(token);
    }
    catch (Exception ex)
    {
        Log.Error(TAG, ex.Message);
    }

    var tags = new List<string>() { Entities.Settings.DeviceId };
    var regID = hub.Register(token, tags.ToArray()).RegistrationId;

    Log.Debug(TAG, $"Successful registration of ID {regID}");
}
}

如何将我的应用程序注册为 FCMv1?

android firebase-cloud-messaging azure-notificationhub
1个回答
0
投票

你能让这个发挥作用吗?

© www.soinside.com 2019 - 2024. All rights reserved.