【问题标题】:Xamarin iOS Push notifications do not work in Production but work fine in DevelopmentXamarin iOS 推送通知在生产中不起作用,但在开发中工作正常
【发布时间】:2018-11-02 22:02:19
【问题描述】:

我在 Azure 中托管了一个 Web API。 Web API 具有 POST 方法,当使用 Postman 将字符串正文消息发布到 Web API url 时,消息在 开发 中完美地发送到移动设备。这是它的代码:

[Authorize]
        [HttpPost, Route("send")]
        public async Task<NotificationOutcome> Post([FromBody]string message)
        {

            string hubName = "hubname";
            string hubNameDefaultShared = "endpointAddress";

            NotificationHubClient hub = NotificationHubClient
                            .CreateClientFromConnectionString(hubNameDefaultShared, hubName, enableTestSend: true);

            string installationId = string.Empty;

            var templateParams = new Dictionary<string, string>
            {
                ["messageParam"] = message
            };

            NotificationOutcome result = null;
            if (string.IsNullOrWhiteSpace(installationId))
            {
                result = await hub.SendTemplateNotificationAsync(templateParams).ConfigureAwait(false);
            }
            else
            {
                result = await hub.SendTemplateNotificationAsync(templateParams, "$InstallationId:{" + installationId + "}").ConfigureAwait(false);
            }

            return result;
        }

当我切换到 Production 并从商店下载应用程序时,使用 Postman 发布到上面的 Web API 时没有收到推送通知:

我已经完成的步骤:

  1. 移动应用和通知服务扩展的应用 ID。
  2. 在两者上都启用了推送通知,并在 Apple 开发者网站上为两者创建了开发 SSL 推送通知证书和生产推送通知证书。
  3. 在我的钥匙串中,我右键单击“Apple Push Services: MyMobileApp”(生产)并导出 p12。
  4. 将 p12 证书上传到 APNS 下的 Azure Notification Hub,并将 Notification Hub 从 Sandbox 切换到 Production。
  5. 为移动应用和通知服务扩展的开发和生产创建了供应配置文件。
  6. 编辑了移动应用和通知扩展服务的 Entitlement.plist 并将“aps-environment”设置为“production”
  7. 在 info.plist 中为每个选择了生产证书和生产配置。
  8. 创建 ipa 文件并上传到商店。

关于通知中心,我需要对 Web API 做些什么来将其设置为生产环境吗?这些是使用 p12 证书将通知中心设置为生产的所有步骤还是我错过了什么?

【问题讨论】:

    标签: azure xamarin.ios apple-push-notifications


    【解决方案1】:

    我想我明白了。问题似乎是我在开发模式下使用手机进行测试。我的手机已注册开发设备令牌。在生产模式下从商店下载应用程序时,该令牌不再有效,我的手机没有收到通知。不知何故,即使在删除了随 Visual Studio 安装的应用程序并从商店下载了该应用程序之后,我的设备仍然与开发令牌相关联。

    我在此处的 Azure 文档网站链接上找到了这个:

    https://docs.microsoft.com/en-us/azure/notification-hubs/notification-hubs-push-notification-faq

    "如果您的 hub 最初配置了 Apple 沙盒证书,然后重新配置为使用 Apple 生产证书,则原始设备令牌无效。无效令牌会导致推送失败。分离您的生产和测试环境,并为不同的环境使用不同的集线器。”

    因此,最好有两个通知中心,一个用于开发,另一个用于生产。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-04
      • 2015-09-23
      • 2020-06-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多