在 CloudKit 中共享父记录时,子记录未显示在共享数据库中

Child records not showing in the Shared Database when sharing the Parent record in CloudKit

我有一个可以与其他用户共享记录的应用程序,当我共享一条记录时一切正常,我的问题是当我共享一条有子记录引用它的记录(父记录)时,我可以看到用户接受共享后,CloudKit 仪表板中 Shared Database 中的父记录,但我没有看到任何相关的子记录。

根据 Stack Overflow 上的 WWDC 视频和其他一些线程,当您共享父记录时,子记录会自动共享,但这不是我所看到的,再次,我可以在中看到父记录Shared Database 但没有子记录。

这里概述了如何在 CloudKit Dashboard 中设置应用程序。

在 CloudKit 仪表板中,我有一个 Lists 和一个 Items 记录类型,其中 Lists 记录是一个或多个 Items.在 Items 模式中,我有一个 Reference 字段类型,它保留对其父列表的引用。

这是我用来保存父记录的代码。

func shareList(){        
    let share = CKShare(rootRecord: self.list)

    if let listName = self.list.object(forKey: "name") as? String {
        self.listName = self.list.object(forKey: "name") as? String
        share[CKShare.SystemFieldKey.title] = "Sharing \(listName)" as CKRecordValue?

    } else {
        share[CKShare.SystemFieldKey.title] = "" as CKRecordValue?
    }
    share[CKShare.SystemFieldKey.shareType] = "com.mySite.lists" as CKRecordValue

    let sharingViewController = UICloudSharingController(preparationHandler: {(UICloudSharingController, handler: @escaping (CKShare?, CKContainer?, Error?) -> Void) in
        let modRecordsList = CKModifyRecordsOperation(recordsToSave: [self.list, share], recordIDsToDelete: nil)

        modRecordsList.modifyRecordsCompletionBlock = {
            (record, recordID, error) in

            handler(share, CKContainer.default(), error)
        }
        CKContainer.default().privateCloudDatabase.add(modRecordsList)
    })

     sharingViewController.delegate = self
     sharingViewController.availablePermissions = [.allowPrivate]
     self.navigationController?.present(sharingViewController, animated:true, completion:nil)
}

我错过了什么?共享父记录时我需要做任何额外的设置吗?

我说的对,子记录应该自动与父记录单独共享?

这是一张图片,展示了项目之间的关系,列表在 Private Database 中工作。

您必须使用 setParent 在每个子记录上设置父记录:https://developer.apple.com/documentation/cloudkit/ckrecord/1690507-setparent

像这样:

childRecord.setParent(parentRecord)

希望对您有所帮助。