iOS 平台上的 Xamarin Forms 未收到 Appcenter 推送通知
Appcenter push notifications not received by Xamarin Forms on iOS platform
我已经在 ASP.Net Core Web API 上使用 AppCenter 实现了推送通知。
服务器正在向负责向每个平台推送通知的 AppCenter 发送 HTTP 请求 Android & iOS.
移动应用程序是使用 Xamarin Forms 开发的。
我已遵循 Microsoft 文档 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()
获取应用中心设备 InstallId。
最后,发送推送通知时,没有任何反应。而且我没有任何日志来搜索问题。
有什么我遗漏的吗?
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));
}
我已经在 ASP.Net Core Web API 上使用 AppCenter 实现了推送通知。 服务器正在向负责向每个平台推送通知的 AppCenter 发送 HTTP 请求 Android & iOS.
移动应用程序是使用 Xamarin Forms 开发的。 我已遵循 Microsoft 文档 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()
获取应用中心设备 InstallId。
最后,发送推送通知时,没有任何反应。而且我没有任何日志来搜索问题。
有什么我遗漏的吗?
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));
}