Post

Replies

Boosts

Views

Activity

NSPersistentCloudKitContainer with public database doesn't work and is poorly documented
So I tried the public database feature of NSPersistentCloudKitContainer last year but never really got anywhere so I thought i'd try it again this year. However I've still had basically no luck and I figured now might be a good time to try and document the issues I have had. The documentation for this at https://developer.apple.com/documentation/coredata/mirroring_a_core_data_store_with_cloudkit/creating_a_core_data_model_for_cloudkit mentions shouldInitializeSchema which from what I can gather was removed in a beta version a long ** time ago. It appears to now be a method on the container - container.initializeCloudKitSchema(). Ya'll should update this documentation. initializeCloudKitSchema does not work if you have options.databaseScope = .public on the NSPersistentCloudKitContainerOptions. You get a bunch of errors saying "No authToken received for asset" Turning off the public scope and then calling initializeCloudKitSchema gets you the Record types you need created in the CloudKit console, then removing the initialise code and setting it back to public, it APPEARS to work, but then... The WWDC video from 2020 says that before you can sync you need to add two indexes to each record type recordName and modifiedAt however if you get this far you will have no such fields. After running it a few times and scouring through the logs you will spot a few errors telling you about missing indexes - adding querable index to recordID, and queryable + searchable to modTime gets you something that.... appears to work... kind of. Ok so you get this far, and you insert some object into your store and save them - and they appear on the cloudkit server, huzzah!. Then you delete the app and reinstall it, and the objects appear in your app, huzzah! However you will now start getting a ton of these kinds of errors in your log: com.apple.coredata.cloudkit.zone:__defaultOwner__ = <CKError 0x2814192f0: "Server Rejected Request" (15/2027); server message = "Custom zones are not allowed in public DB"; op = 8F0FD95A1EFB2348; uuid = F1DCD158-BA28-4E20-AD18-723F603A0C00> And if you use your app to add or edit any objects they won't make it to CloudKit any more. However, adding new objects via the console will make them appear in the app. At this point I kinda gave up. Can somebody tell me I am an *****, or does this feature legitimately not work?
9
0
5.4k
Jun ’21