如何获取iOS设备的Azure Notification Hub RegistrationId?

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

我正在将Azure Notification中心实施到跨平台Xamarin应用程序中。我唯一识别注册通知的每个设备的方式是临时存储azure分配给手机的RegistrationId。一旦用户登录,我就将RegstrationId和一些用户的独特特征发送给后端服务。 RegistrationId用于识别电话,然后用户的详细信息将作为标记通知的标签添加到该电话。

这适用于Android,因为我需要做的就是获取registrationId如下:

var regID = hub.Register(token,tags.ToArray())。RegistrationId;

但是,iOS的等效项不起作用,因为类SBNotificationHub不包含任何获取RegistrationId的方法。如何获取iOS设备的Azure RegistrationId?

谢谢。

c# ios xamarin azure-notificationhub
1个回答
0
投票

我相信你可以在RegisteredForRemoteNotifications类中的AppDelegate覆盖中获得设备ID,如this documentation中所述。

尝试将以下内容添加到AppDelegate类:

// Add to top of class file, outside of namespace
using Newtonsoft.Json.Linq;

// Add inside of class
public override void RegisteredForRemoteNotifications(UIApplication application,
NSData deviceToken)
{
    const string templateBodyAPNS = "{\"aps\":{\"alert\":\"$(messageParam)\"}}";

    JObject templates = new JObject();
    templates["genericMessage"] = new JObject
    {
        {"body", templateBodyAPNS}
    };

    // Register for push with your mobile app
    Push push = TodoItemManager.DefaultManager.CurrentClient.GetPush();
    push.RegisterAsync(deviceToken, templates);
}

我认为deviceToken是你在iOS中寻找的东西吗?

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