简体   繁体   English

静默的iCloud更改了后台未收到的通知

[英]Silent iCloud changed notifications not received in background

My app uses a public iCloud database that is synchronised using push notifications. 我的应用程序使用公共iCloud数据库,该数据库使用推送通知进行同步。
The subscription to iCloud notifications uses the following notificationInfo : iCloud通知的预订使用以下notificationInfo

    let notificationInfo = CKNotificationInfo()
    notificationInfo.alertBody = nil
    notificationInfo.shouldSendContentAvailable = true  

The test setup uses 2 iOS devices: 测试设置使用2个iOS设备:

  • The 1st device uses my app to modify the iCloud database. 第一台设备使用我的应用程序来修改iCloud数据库。
  • The 2nd device runs my app either in foreground or (screen turned off) in background mode. 第二台设备在前台运行或在后台模式下(屏幕关闭)运行我的应用程序。 This is done under Xcode control, so that I can set breakpoints. 这是在Xcode的控制下完成的,因此我可以设置断点。 System settings/Notifications of my app: Notifications allowed, shown in notification center & lock screen. 系统设置/我的应用程序通知:允许通知,显示在通知中心和锁定屏幕中。

1st test: 第一次测试:

2nd device: Executes my app in foreground. 第二台设备:在前台执行我的应用程序。

When the 1st device modifies the database, a notification is received in 当第一台设备修改数据库时,将在

func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) 

This is as expected. 这是预期的。

2nd test: 第二次测试:

2nd device: As above, but now the screen is turned off, ie my app is in background. 第二台设备:如上所述,但是现在屏幕已关闭,即我的应用程序处于后台。

When the 1st device modifies the database, a notification is received. 当第一台设备修改数据库时,将收到通知。

Expected behaviour: 预期的行为:
Since shouldSendContentAvailable is set to true in the notification info, the system should wake my app (see docs ). 由于通知信息中的shouldSendContentAvailable设置为true ,因此系统应唤醒我的应用程序(请参阅docs )。 The app should then be given background execution time to download any data related to the push notification, such as the set of records that changed. 然后应该给应用程序后台执行时间,以下载与推送通知相关的任何数据,例如已更改的记录集。 This should be done by calling 这应该通过调用

func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void)  

Actual behaviour: 实际行为:
An alert is displayed in the lock screen, saying „iCloud changed, slide to open“. 锁定屏幕中会显示一条警报,提示“ iCloud已更改,请滑动以打开”。 If I swipe this alert and unlock the device, only then is this function actually called. 如果我滑动此警报并解锁设备,则只有该函数真正被调用。

My problem: 我的问题:
I want to use silence pushes from iCloud to update the local data of my app. 我想使用来自iCloud的静默推送来更新我的应用程序的本地数据。 So why is an alert with the default message body „iCloud changed“ shown on the lock screen, although I set shouldSendContentAvailable = true ? 那么,尽管我设置了shouldSendContentAvailable = true为什么在锁定屏幕上仍显示带有默认消息正文“ iCloud shouldSendContentAvailable = true

My fault, although not obvious: 我的错,虽然不明显:

My CloudKit Dashboard shows that there is my subscription type. 我的CloudKit仪表板显示有我的订阅类型。 But for some reason, the dashboard does not show any subscription. 但是由于某种原因,仪表板不显示任何订阅。 I thus fetched all existing subscriptions using 因此,我使用获取了所有现有的订阅

private func getAllSubscriptionIDs(completion: @escaping (_ subscriptionIDs:[String]?, _ error: Error?) -> Void) {
    let database = CKContainer.default().publicCloudDatabase
    database.fetchAllSubscriptions { subscriptions, error in
        guard error == nil else {
            completion(nil, error)
            return
        }
        guard let subscriptions = subscriptions else {
            completion([], nil)
            return
        }
        let subscriptionIDs = subscriptions.map{ $0.subscriptionID }
        completion(subscriptionIDs, nil)
    } // fetchAllSubscriptions
}  

I got 5 existing subscriptions back, and one of them had an alert body " iCloud changed " with shouldSendContentAvailable = false . 我收回了5个现有的订阅,其中一个订阅主体具有shouldSendContentAvailable = falseiCloud changed ”。

Obviously, I did use these subscriptions earlier during the development, and I did not delete them since they were not shown in the dashboard. 显然,我在开发过程中的早期就使用了这些订阅,并且由于它们没有显示在仪表板上,所以我没有删除它们。
Deleting them fixed the problem. 删除它们可以解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当应用程序在 iOS 中运行时,是否在关闭后台通知的情况下收到静默通知? - Are silent notifications received with background notifications turned off, while application is running in iOS? 仅在手机打开时收到静默通知 - Silent notifications only received when phone is open iOS 应用程序未收到通知,但仅收到静默通知 - iOS app not receiving notifications but ONLY silent notification is received 在后台获取可达性更改的通知 - Getting Reachability changed notifications in the background 静默通知 - Silent notifications 在 macOS Catalina(Catalyst 应用程序)上未收到静默推送通知(后台) - Silent push notification (background) not received on macOS Catalina (Catalyst app) 使用静默推送通知将iOS应用保持在“背景”状态 - Using silent push notifications to keep an iOS app in “Background” state 在iOS 7上收到远程通知(静音推送)时执行后台任务 - Executing background task upon receiving Remote Notifications(Silent Push) on iOS 7 Swift-如何在后台获取某些静默通知,在前台获取其他静默通知? - Swift -How to get certain silent notifications in the background and others in the foreground? 强制退出应用程序在后台模式下的无提示通知 - Silent notifications in Background Mode on force-quit apps
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM