I'm adding CloudKit sharing to an app that already uses NSPersistentCloudKitContainer successfully. Private-database sync works flawlessly across my devices. But every attempt to create a share hangs: container.share(_:to:) never returns and never invokes its completion handler. No error is thrown, nothing prints, the operation simply stalls indefinitely.
Environment:
Xcode 26, iOS 26.5, iPhone 16
Paid Individual developer account
Single NSPersistentCloudKitContainer, two stores (private + shared)
What works:
Private database sync across multiple devices (iPhone + iPad) is reliable
eventChangedNotification reports setup/import/export events succeeding continuously
CloudKit schema was initialized via initializeCloudKitSchema() and record types appear in the CloudKit Console
The problem:
Calling share on a root object hangs. I've reproduced the identical hang with all three API variants:
async/await: try await container.share([object], to: nil) — never returns
Completion handler: container.share([object], to: nil) { ... } — closure never fires
UICloudSharingController preparation-closure initializer — the closure never fires, controller presents an empty sheet
A log line immediately before the share call prints; a log line inside the completion/closure never does.
My two-store setup (per WWDC21 session 10015):
swiftlet sharedURL = privateDesc.url!
.deletingLastPathComponent()
.appendingPathComponent("YerBoat-Shared.sqlite")
let sharedDesc = NSPersistentStoreDescription(url: sharedURL)
let sharedOptions = NSPersistentCloudKitContainerOptions(containerIdentifier: "iCloud.com.example.app")
sharedOptions.databaseScope = .shared
sharedDesc.cloudKitContainerOptions = sharedOptions
sharedDesc.setOption(true as NSNumber, forKey: NSPersistentHistoryTrackingKey)
sharedDesc.setOption(true as NSNumber, forKey: NSPersistentStoreRemoteChangeNotificationPostOptionKey)
container.persistentStoreDescriptions = [privateDesc, sharedDesc]
Possibly relevant: the objects I'm trying to share (and their related records via cascade relationships) were all created before I added the sharing/shared-store code. Could existing records in the default zone fail to migrate into a shareable zone, causing the hang?
Questions:
What causes share() to hang silently with no error and no completion?
Does sharing require records to be created after the shared store exists, or should existing private-database records be shareable?
Is there a required step between initializeCloudKitSchema() and the first share() call that I'm missing?
I've reviewed WWDC21-10015 and TN3164. Any guidance appreciated.
1
0
16