CloudKit initial sync and background audio leads to high CPU app termination

I have a music app that can play in the background, using AVQueuePlayer. I'm in the process of adding support for CloudKit sync of the CoreData store, switching from NSPersistentContainer to NSPersistentCloudKitContainer.

The initial sync can be fairly large (10,000+ records), depending on how much the user has used the app. The issue I'm seeing is this:

  • ✅ When the app is in the foreground, CloudKit sync uses a lot of CPU, nearly 100% for a long time (this is expected during the initial sync).

  • ✅ If I AM NOT playing music, when I put the app in the background, CloudKit sync eventually stops syncing until I bring the app to the foreground again (this is also expected).

  • ❌ If I AM playing music, when I put the app in the background, CloudKit never stops syncing, which leads the system to terminate the app after a certain amount of time due to high CPU usage.

Is there any way to pause the CloudKit sync when the app is in the background or is there any way to mitigate this?

Here's a CPU capture of the different states.

Most likely the same problem as here: https://developer.apple.com/forums/thread/687877

Me and other people with large core data store (and lot of relations) have been waiting since iOS 15 beta 4 for it to be fixed

Let's hope it's fixed on iOS 15.1

I've had the exact same problem, except running in background recording location updates. In the end I had to disable Core Data Cloud Kit sync. Was this ever fixed?

CloudKit initial sync and background audio leads to high CPU app termination
 
 
Q