ios - CloudKit 仪表板未更新

标签 ios iphone swift cloudkit dashboard

我正在制作一个应用程序来存储每个用户的评论,然后将它们显示在我的应用程序中。 (就像餐厅评级应用程序一样)但是,当用户输入评论并点击提交时,仪表板上似乎没有显示任何内容。

每个记录类型都设置为可查询,但是当我单击查询结果时,它会给出错误,我应该将索引设置为可查询。

这是我的代码。(Swift)

@IBAction func OnSubmitTouched(_ sender: UIButton) {
    if (textField.text != ""){

        let newComment = CKRecord(recordType: "Comment")
        let publicDB = CKContainer.default().publicCloudDatabase
        newComment.setValue(textField.text!, forKey: "comment")
        CKContainer.default().fetchUserRecordID { recordID, error in
            guard let recordID = recordID, error == nil else {
                // error handling magic
                return
            }

            //let userID = CKContainer fetchUserRecordIDWithCompletionHandler:
            publicDB.save(newComment){
                rec ,err in
                if let error = err {

                    print(err.debugDescription)
                    return
                }

                publicDB.fetch(withRecordID: recordID) { record, error in
                    guard let record = record, error == nil else {
                        // show off your error handling skills
                        print(rec!["comment"]!)
                        return
                    }
                    print("The user record is: \(record)")
                }
            }
        }

        let predicate = NSPredicate(value: true)
        let query = CKQuery(recordType: "Comment", predicate: predicate)
        let operation = CKQueryOperation(query: query)

        var commentRecords: [CKRecord] = []

        operation.recordFetchedBlock = { record in
            commentRecords.append(record)
        }

        operation.queryCompletionBlock = { cursor, error in
            print(commentRecords)
        }

        CKContainer.default().publicCloudDatabase.add(operation)

最佳答案

嗯...CloudKit 非常擅长在保存失败时告诉您。您的任何错误是否返回任何内容?

此外,CKContainer.default() 返回的容器 ID 是否与您在仪表板中查看的容器 ID 相同?

我要检查的最后一件事是,您是否在 iOS 设备和 CloudKit 仪表板上使用相同的 Apple ID,以便查看同一用户的数据?

关于ios - CloudKit 仪表板未更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51927441/

相关文章:

iOS TableView 和 prototypecell 约束无法正常工作

ios - 更新iOS应用程序后,是否会删除库/缓存中的文件?

iPhone "_OBJC_CLASS_"编译错误

iphone - AVPlayer 不播放视频文件

iphone - 如何设置表格 View 单元格适应标签?

ios - Swift Charts - 明确识别特定条目

ios - 停止功能 Corona SDK

ios - 为什么 UIView 的 CALayer.speed 为零会阻止 UIAlertController 的按钮工作?

ios - 如何在 SwiftUI 中的两个 View 模型之间共享已发布的模型?

ios - 允许 UIAnimations 中的 UITapGestureRecognizer