【问题标题】:How do I obtain the Azure Notification Hub RegistrationId for iOS devices?如何获取适用于 iOS 设备的 Azure 通知中心 RegistrationId?
【发布时间】:2019-06-25 04:18:26
【问题描述】:

我正在将 Azure 通知中心实现到跨平台 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】:

    我相信您可以在AppDelegate 类中的RegisteredForRemoteNotifications 覆盖中获得设备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 中寻找的东西?

    【讨论】:

    • 设备令牌和registrationId不同,registrationid是存储在azure通知中心的手机。我希望能够将注册设备存储在设备上,然后将其发送到后端服务,作为在集线器上的所有注册设备中查找设备的快速有效的方法。编辑 - 不知道我为什么这么解释,我刚刚注意到你的个人资料!
    • 尽管有我的个人资料,但我不是 Azure 通知中心 API 方面的专家。不过,我会看看我能找到什么。
    • 做了一些研究,我认为iOS没有像Android那样的注册ID。 Azure 通知服务类似于原生 platofrms 通知服务的转发器。 FCM for Android 确实使用了注册 ID。见docs.microsoft.com/en-us/xamarin/android/data-cloud/…。但是查看 iOS 的文档,没有提到任何注册 ID,只有一个设备令牌。见docs.microsoft.com/en-us/xamarin/ios/platform/…
    • 看来我是正确的,在 Xam.iOS 的 Google FCM 文档中得到证实:github.com/xamarin/GoogleApisForiOSComponents/blob/master/…
    猜你喜欢
    • 2016-12-31
    • 1970-01-01
    • 2018-05-29
    • 2023-01-06
    • 2013-10-10
    • 1970-01-01
    • 2020-02-14
    • 2015-12-27
    • 2021-05-08
    相关资源
    最近更新 更多