1

I am currently testing the NSPersistentCloudKitContainer. I have strictly followed the guidelines of the new documentation. Basically everything works as desired. I use the option NSPersistentStoreRemoteChangeNotificationPostOptionKey on the description to receive Updates from the remote data store. But the updates from the remote database are only delivered if the app is in the foreground. But I would like to update my widget based on a data change in the backend.

Does anyone has an idea how to solve this issues?

What I did so far:

  • Background Modes in Capabilities are enabled
  • Push Notifications are enabled
  • i called registerForRemoteNotifications
  • HistoryTracking and RemoteChange Option are enabled on the description of the PersistentStore

Syncing works in foreground ✅

Syncing does not work if App is in Background ❌

Edit: 09.09.2020

It seems that there is nothing that we can do at the moment. Apple Developer Support answered my question some days ago

Thank you for contacting Apple Developer Technical Support (DTS). 

The behavior and resulting limitations you describe are by design.

If you believe an alternative approach should be considered by Apple, we encourage you to file an enhancement request with information on how this design decision impacts you, and what you’d like to see done differently.

Although there is no promise that the behavior will be changed, it is the best way to ensure your thoughts on the matter are seen by the team responsible for the decision.

While a Technical Support Incident (TSI) was initially debited from your Apple Developer Program account for this request, we have assigned a replacement incident back to your account.

Sebastian Boldt
  • 5,283
  • 9
  • 52
  • 64
  • It does work in the background, perhaps give more detail on how you are testing it. – malhal Sep 11 '20 at 21:39
  • I am testing it by deleting a set of data using the CloudKit Dashboard and wait for the didReceiveRemoteNotification call inside the AppDelegate. If I put the App into the Foreground the functions gets called and the Data will be updated accordingly, if I keep the App in Background nothing happens. – Sebastian Boldt Sep 13 '20 at 15:57
  • What version of Xcode, what SDK, what device, what version of iOS is it running? And are you running the debugger when you test or running the app normally and using Console to examine debug output? – malhal Sep 14 '20 at 17:07
  • I am using Xcode 12 Beta 6 and iOS 14 GM. I am running the App without attaching the Debugger to it. – Sebastian Boldt Sep 16 '20 at 18:34
  • Ok and what device? – malhal Sep 17 '20 at 19:19
  • With background do you mean a background thread aswell? Syncing a huge amount of data keeps blocking my app and even crashing, as i'm performing some calculations in the background thread. – EMart Sep 17 '20 at 19:21
  • With "background" I mean the App-State in background (not foreground) – Sebastian Boldt Sep 17 '20 at 19:22
  • It seems background push notifications are either not working at all on iOS 14 (the public release they were broken and they supposedly have fixed them again in 14.2 beta however I'm not sure about that) or the ones for the NSPersistentCloudKitContainer that have the ck payload are just not allowed to launch the app in the background, which given the respone you got from Apple is most likely the case. https://developer.apple.com/forums/thread/660149 – malhal Sep 22 '20 at 16:24
  • After upgrading iOS to 14.2 it works sometimes but it is not really reliable. – Sebastian Boldt Oct 07 '20 at 19:33
  • In my testing background sync seems to be working more reliably in iOS 16 vs 15. I'm documenting my findings here: https://developer.apple.com/forums/thread/651648?answerId=717036022#717036022 – Jordan H Jun 12 '22 at 17:44

0 Answers0