CloudKit Dashboard not updating

邮差的信 提交于 2019-12-24 18:31:12

问题


I'm making an app to store every users' comments and then dısplay them in my app. (just like a restaurant rating app) However when a user enters a comment and hits submit, nothing seems to appear on dashboard.

Every record type is set to queryable yet when I click on query results it gives me the error that I should set my indexes to queryable.

Here is my code.(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)

回答1:


Hmm... CloudKit is pretty good about telling you when a save failed. Are any of your errors returning anything?

Also, does CKContainer.default() return the same container ID as the one you're looking at in the dashboard?

The last thing I'd check is are you using the same Apple ID on the iOS device and the CloudKit dashboard so that you're looking at the same user's data?



来源:https://stackoverflow.com/questions/51927441/cloudkit-dashboard-not-updating

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!