如何通过 Azure 通知中心应用服务 SDK 或手动为 Xamarin Forms 应用注册设备?

How to Register a device through Azure Notification Hub App Service SDK or manually for a Xamarin Forms App?

所以我正在使用 Azure 通知中心,并且我按照他们提到的使用 FCM 进行 Android 的教程,配置它并使用他们的 API 密钥,并创建一个iOS 的证书,工作完美

但问题是我正在处理 Xamarin 表单,我想知道我是否可以通过 API 手动进行注册,我已经在我的 API 服务

 public async Task<string> RegisterDevice([FromBody] string handle = null)
    {
        string newRegistrationId = null;
        //newRegistrationId = await hub.CreateRegistrationIdAsync();
        //// make sure there are no existing registrations for this push handle (used for iOS and Android)
        //if (handle != null)
        //{
        //    var registrations = await hub.GetRegistrationsByChannelAsync(handle, 100);

        //    foreach (var registration in registrations)
        //    {
        //        if (newRegistrationId == null)
        //        {
        //            newRegistrationId = registration.RegistrationId;
        //        }
        //        else
        //        {
        //            await hub.DeleteRegistrationAsync(registration);
        //        }
        //    }
        //}
        newRegistrationId = await hub.CreateRegistrationIdAsync();
        return newRegistrationId;
    }

但我无法理解设备如何链接到此注册 ID and/or 什么是 pns 句柄,我知道缩写但我不知道如何在这种情况下使用它或如果有必要吗? 任何帮助将不胜感激

注册Azure Notification Hub时,登录后如果想请求Push权限,需要调用RegisterForRemoteNotifications();(iOS)&CreateNotificationChannel();(Android) 登录后。 你问的是需要几个步骤 - 您必须创建一个像 this 这样的 DependencyService,这将需要创建一个像 IPushRegistrationService 这样的接口,并带有 RegisterForPush() 函数,该函数基本上会在登录后调用:

var pushService = DependencyService.Get<IPushRegistrationService>();
pushService.RegisterForPush();