简体   繁体   English

如何在 CloudKit 中获取用户记录?

[英]How do I get user record in CloudKit?

I can fetch the userRecordID, but I get an error whenever I try to fetch the record associated with that ID.我可以获取 userRecordID,但每当我尝试获取与该 ID 关联的记录时都会出错。 Any suggestions?有什么建议么? Code and error below:下面的代码和错误:

myContainer.fetchUserRecordID { (thisID, thisError) in
            if let userError = thisError {
                print("DEBUG: error getting user id; \(userError)")
            } else {
                if let userID = thisID {
                    self.publicDatabase.fetch(withRecordID: userID, completionHandler: { (fetchedUser, fetchedError) in
                        if let thisError = fetchedError {
                            print("DEBUG: error getting user record; \(thisError)")
                        }

DEBUG: error getting user record; <CKError 0x174045010: "Internal Error" (1/5001); "Couldn't get a PCS object to unwrap encrypted data for field encryptedPublicSharingKey: (null)">

Error in the code, or my fault for trying beta software (iOS 10, Swift 3 & xCode-beta 8.0 beta 2 (8S162m)代码错误,或者我尝试测试版软件的错(iOS 10、Swift 3 和 xCode-beta 8.0 beta 2 (8S162m)

From your example it is not clear if self.publicDatabase is equal to myContainer.publicCloudDatabase .从您的示例中不清楚self.publicDatabase是否等于myContainer.publicCloudDatabase

Make sure you fetch it from the same container's database, otherwise it will obviously not work.确保从同一个容器的数据库中获取它,否则它显然无法正常工作。

myContainer.fetchUserRecordID { userID, error in
    guard error == nil else {
        print("DEBUG: error getting user id; \(userError)")
        return
    }
    guard let userRecID = userID else {
        print("DEBUG: Can't unwrap userID")
        return
    }
    myContainer.publicCloudDatabase.fetch(withRecordID: userRecID, completionHandler: { (fetchedUser, fetchedError) in
        //handle the error and the user
        print("DEBUG: User fetch FINISHED!", fetchedUser)
    })
}

I needed to change from publicDatabase to privateDatabase. 我需要从publicDatabase更改为privateDatabase。

self.publicDatabase.fetch(withRecordID: userID, completionHandler: { (fetchedUser, fetchedError) in

to

self.privateDatabase.fetch(withRecordID: userID, completionHandler: { (fetchedUser, fetchedError) in

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM