且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

CloudKit 推送通知,后台运行的应用程序

更新时间:2023-02-26 21:09:56

当您进入应用设置功能时,您是否为后台模式启用了远程通知?

When you go to your app settings capabilities, do you have remote notifications enabled for background modes?

看这个截图:

除此之外,您是否注册了所有通知类型,如下所示:

Besides that, did you register for all notification types like this:

application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes: .Alert | .Badge | .Sound, categories: nil))
    application.registerForRemoteNotifications()

在您的订阅中,您是否为 CKNotificationInfo 发送了 alertBody 或 alertLocalizationKey?如果您这样做,那么您已经从操作系统收到通知,您无需设置本地通知.

And in your subscription, do you send an alertBody or alertLocalizationKey for the CKNotificationInfo? If you do that, then you will already get a notification from the OS and you don't need to setup a local notification.

更新:正如下面提到的 Porton,这个问题是通过填写 alertBody 解决的.

Update: As Porton mentioned below, this issue was solved by filling in the alertBody.