UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

SOLVED: "Custom Zone in Public DB" error when using iOS15 / Xcode 13

Forums > Swift

Hi All

I am hitting an issue when developing an app that uses the CloudKit Public DB. I am relatively new to this, and I may be doing something wrong. I have distilled the issue to use just the template app that comes when you create a new Core Data with iCloud app, and detailed the steps below. My question is basically, am I doing something stupid? If I'm not then seems likely it's a bug in Xcode and I'll just have to wait.

In a nutshell, syncing to the public DB works for the first run of the app only. Stopping and restarting the app seems to throw errors and cause the mirroring delegate to fail.

Steps are:

  1. Create App with Use Core Data and Host in ICloud - interface is SWiftUI

2.In project signings and capabilities add iCloud and Background Modes

  1. In nearly appeared iCloud section enable Cloudkit and choose or create a container

  2. In newly appeared Background Modes section enable Remote Notifications

  3. In persistence.swift add :

import CloudKit

  1. Still in persistence.swift add the following:

    guard let description = container.persistentStoreDescriptions.first else
    {
        fatalError("Somethng bad happened")
    }
    
    description.cloudKitContainerOptions?.databaseScope = .public

    I have added this just before the following line:

    container.loadPersistentStores(completionHandler: { (storeDescription, error) in

    1. In he schema model, highlight the default configuration and check in the data model inspector that "use cloudkit" is checked

    2. Run the app and hit the + a few times to add some records.

    3. Check on Cloudkit Dashboard in the public database in the container selected / created in step 3. You will need to created indexes on recordName / modifiedTimestamp in order to view the records on the CD_Item entity. Unfortunately, my Cloudkit Dashboard seems to have changed. Whereas before I could click Indexes and then add the recordName (queryable) / moodifiedTimestamp (queryable / sortable), I don't seem to be able to select these fields anymore. If you are able to query though, you should see that the records after a minute or so all appear in the public database. No errors are reported in the console window on Xcode.

    4. Stop and restart the app.

    5. This time when I click the plus button, the timestamp records are not being uploaded to the public DB (though they do appear on the screen) and the console is reporting error messages similar to that below:

CoreData: CloudKit: CoreData+CloudKit: -NSCloudKitMirroringDelegate _finishedRequest:withResult:: Finished request: <NSCloudKitMirroringExportRequest: 0x283666bb0> 9F190C45-7713-4ACE-96DB-867D99FF62ED with result: <NSCloudKitMirroringResult: 0x2838b9e20> success: 0 madeChanges: 0 error: Error Domain=NSCocoaErrorDomain Code=134406 "Request '9F190C45-7713-4ACE-96DB-867D99FF62ED' was aborted because the mirroring delegate never successfully initialized due to error: <CKError 0x2836aba50: "Partial Failure" (2/1011); "Failed to modify some record zones"; uuid = 3F399390-1F10-4198-BBBF-F3BD76E99591; container ID = "iCloud.XXXXXXXXXXX"; partial errors: { com.apple.coredata.cloudkit.zone:defaultOwner = <CKError 0x2836a5290: "Server Rejected Request" (15/2027); server message = "Custom zones are not allowed in public DB"; op = 943153DA6AC169A1; uuid = XXXXXXXXXXXXXXXXXXXXXXXX> }>" UserInfo={NSLocalizedFailureReason=Request '9F190C45-7713-4ACE-96DB-867D99FF62ED' was aborted because the mirroring delegate never successfully initialized due to error: <CKError 0x2836aba50: "Partial Failure" (2/1011); "Failed to modify some record zones"; uuid = 3F399390-1F10-4198-BBBF-F3BD76E99591; container ID = "iCloud.XXXXXXXXX"; partial errors: { com.apple.coredata.cloudkit.zone:defaultOwner = <CKError 0x2836a5290: "Server Rejected Request" (15/2027); server message = "Custom zones are not allowed in public DB"; op = 943153DA6AC169A1; uuid = XXXXXXXXXXXXXXXXXXXXXXXXX> }>}

Thanks in advance for any assistance anyone can offer,

Ian

3      

I running in exactly the same issue since days. You've find a solution in the meanwhile?

4      

Same for me here...

" UserInfo={NSLocalizedFailureReason=Request '' was aborted because the mirroring delegate never successfully initialized due to error: <CKError 0x16b42260: "Partial Failure" (2/1011); "Failed to modify some record zones"; uuid = ; container ID = "XXX"; partial errors: { com.apple.coredata.cloudkit.zone:defaultOwner = <CKError 0x1553ec20: "Server Rejected Request" (15/2027); server message = "Custom zones are not allowed in public DB"; op = 9C654E53C29811EB; uuid = > }>}

3      

Hi Folks - good to know I am not alone! The issue now seems to be resolved in iOS 15.1. I installed Xcode 13.1 first and this did not solve the issue, but when I upgraded my test device, it worked. Whether it was iOS 15.1 or the combination of the two, I can't say for certain.

Hope this works for you too.

4      

A follow-up. I'm still not convinced this is 100% correct. My code was working fine again, then seemed to deteriorate and then stopped working altogether. I have been able to get it going again. It appears to be linked to the Cloudkit schema. The initialise of the schema alone does not appear to be enough. I am pretty sure it was before, because I would do the intialise, then manually create the indexes after to see my records. To get this working again I had to pre-create the indexes as I was getting error messages saying the mirroring delegate had not successfully initialized due to error

"Invalid Arguments" (12/2015); server message = "Field 'recordName' is not marked queryable";

So recordID needs a queryable index, and modTime needs queryable and sortable. I also noticed that there seems to be a glitch in the Cloudkit Dashboard, and if you add the two indexes for modTime at the same time, one of them won't appear. So make sure you check after. If this continues to plague me as it has now for over a month, I'll add an update. If anyone spots that I am making a newb error, please leave a comment and let me know.

Cheers,

Ian

3      

@snark2021 Thanks for your response and solution. I can confirm that it works with 15.1 and Xcode 13.1.

3      

Hacking with Swift is sponsored by Essential Developer

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until April 28th.

Click to save your free spot now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.