Search code examples
core-datacloudkit

Trying to create a public CKShare to a private database


I am trying to create a CKShare to the private database but with a public permission, meaning the user only needs to have the url and doesn't need to be specifically invited. The code I use to create the share is as follows but I always end up with a private share.

private func createShare(_ school: School) async
    {
        do
        {
            let (_, share, _) = try await CoreDataStack.shared.persistentContainer.share([school], to: nil)
            share[CKShare.SystemFieldKey.title] = school.name
            share.publicPermission = CKShare.ParticipantPermission.readWrite
            self.share = share
        } catch
        {
            error.log("ContentView")
            print("Failed to create share")
        }
    }

Any suggestions?


Solution

  • This isn't the full answer but it solves my problem. I forgot or failed to notice that on the Share controller there is a Share Options link that allows me to set the share to "Anyone with the link". Ideally what I'd like would be for that to be the default, but as I say, this solves the problem for now.