【问题标题】:Appcenter push notifications not received by Xamarin Forms on iOS platformiOS 平台上的 Xamarin Forms 未收到 Appcenter 推送通知
【发布时间】:2019-05-11 10:16:21
【问题描述】:

我已经在 ASP.Net Core Web API 上使用 AppCenter 实现了推送通知。 服务器向 AppCenter 发送 HTTP 请求,AppCenter 负责将通知推送到 Android 和 iOS 各个平台。

移动应用程序是使用 Xamarin Forms 开发的。 我已经关注了微软文档here

Xamarin Android 应用程序像魅力一样接收每一个推送通知。

问题出在 Xamarin iOS 应用程序上。设备未收到任何推送通知。

这是我所做的 iOS 设置:

  • 在生产(非开发)权利中启用推送通知
  • 在我的 Apple 开发者帐户中为推送通知创建了一个 APN 密钥用于生产
  • 为 AppCenter 设置提供了 iOS APN 密钥(带有 APP ID、前缀...)
  • 在 info.plist 中以后台模式启用远程通知
  • 通过将 AppCenterAppDelegateForwarderEnabled 键添加到 info.plist 来禁用 swizzling
  • 在 AppDelegate 中重写 DidReceiveRemoteNotification 并实现方法 RegisteredForRemoteNotifications 、 FailedToRegisterForRemoteNotifications

然后,我已成功将应用发布到生产模式的 TestFligth。

启动应用程序时,我通过调用方法AppCenter.GetInstallIdAsync() 获取appcenter 设备InstallId。

最后,当推送通知被发送时,什么也没有发生。而且我没有任何日志来搜索问题。

我错过了什么让它工作吗?

【问题讨论】:

  • 您是否尝试使用您获得的安装 ID 从 App Center 控制台而不是后端发送推送?
  • 是的,我尝试了所有 iOS 注册设备,但仍然没有收到任何内容
  • 您是在使用真机进行测试吗?检查步骤here
  • 是的,我正在通过 TestFligth 使用真实设备进行测试。您提到的链接是直接使用 APNS 时提供的步骤,但在我的情况下,我使用的是 AppCenter,它执行注册推送通知的所有必要步骤......此外,我们启动了 iOS 应用程序,我有一个警告弹出窗口询问允许我的应用显示通知。意味着 AppCenter 正在完成这项工作......
  • 我之前没用过AppCenter。有很多可能导致这个问题。我建议您检查您是否使用的是生产认证而不是开发认证。

标签: c# ios xamarin.forms push-notification visual-studio-app-center


【解决方案1】:

AppCenter 为每个平台提供不同的 AppSecret。 你应该这样做:

        if (Xamarin.Forms.Device.RuntimePlatform == Xamarin.Forms.Device.iOS)
        {
            //Start AppCenter Push notification with iOS app secret
            AppCenter.Start("xxxxxxxxxxxxxxxxxxxxxxx", typeof(Push));
        }
        else if (Xamarin.Forms.Device.RuntimePlatform == Xamarin.Forms.Device.UWP)
        {
            //Start AppCenter Push notification with UWP app secret
            AppCenter.Start("xxxxxxxxxxxxxxxxxxxxxxx", typeof(Push));
        }
        else if(Xamarin.Forms.Device.RuntimePlatform == Xamarin.Forms.Device.Android)
        {
            //Start AppCenter Push notification with Android app secret
            AppCenter.Start("xxxxxxxxxxxxxxxxxxxxxxx", typeof(Push));
        }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-05-23
    • 1970-01-01
    • 2022-11-08
    • 1970-01-01
    • 1970-01-01
    • 2021-06-13
    • 1970-01-01
    • 2016-08-16
    相关资源
    最近更新 更多