ios - 查询 CloudKit 用户记录给出 "Can' t 查询系统类型”

标签 ios objective-c swift cloudkit

好的,所以我在 CloudKit 上构建了一个游戏,我想查询排行榜得分前 50 名的用户。

// Create a CKQuery
let predicate = NSPredicate(value: true)
let sortDescriptor = NSSortDescriptor(key: "score", ascending: false)
var query = CKQuery(recordType: "Users", predicate: predicate)
query.sortDescriptors = [sortDescriptor]

// Create a query operation
var queryOperation = CKQueryOperation(query: query)
queryOperation.resultsLimit = 50
queryOperation.recordFetchedBlock = { (record: CKRecord!) -> Void in
    self.records.append(record)
}
queryOperation.queryCompletionBlock = { (cursor: CKQueryCursor!, error: NSError!) in
    // Log an error and show and alert
    if error != nil {
        println("Error querying for leaderboard: \(error)")
        var alert = UIAlertController(title: "Unable Donwload Leaderboard", message: "Unable to download the leaderboard at this time. Please try agin later.", preferredStyle: UIAlertControllerStyle.Alert)
        alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil))
        self.presentViewController(alert, animated: true, completion: nil)
        return
    }

    // Update the records array and refresh the table view
    dispatch_async(dispatch_get_main_queue(), { () -> Void in
        self.tableView.reloadData()
    })
}

// Start the operation
database.addOperation(queryOperation)

这不会向 records 数组添加任何记录,并且会在完成 block 中返回此错误:

<CKError 0x1553cc10: "Permission Failure" (10/2007); server message = "Can't query system types"; uuid = 3349514B-02EC-40D7-B716-585D4ADD3128; container ID = "iCloud.com.MyCompany.MyApp">

最佳答案

我在 Apple 的文档中找到了这个问题的答案。特别是关于 CKQueries. 的文档

在对 initWithRecordType:predicate: 的讨论中说:

You cannot query for user records and executing a query where the record type is set to CKRecordTypeUserRecord results in an error. You must fetch user records directly using their ID.

所以我猜 CloudKit 不会让你查询用户记录。

我最终添加了一个引用用户的分数记录。我对此进行了查询,然后我可以通过他们的 ID 获取用户。

关于ios - 查询 CloudKit 用户记录给出 "Can' t 查询系统类型”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27510024/

相关文章:

iphone - 从 objective-c 中包含 html 标签的字符串中提取内容

ios - Pan 手势识别器 : Location of touch crashes once the pan gesture is released

ios - RealmSwift 查询中带有内部对象引用的谓词问题

iphone - IB 自定义 UITableViewCell - 单元格和详细文本的动态高度

objective-c - 从 sqlite 数据库解析 blob

iphone - 如何消除错误 服务无效 请检查您的设置并尝试

ios - 在 iOS 应用中唯一标识 SSL 握手

iOS自动布局-将位于tableviewcell内的 View 移动到屏幕中央

swift - 同步后无法加载 Realm 对象 : realm is empty despite writing

ios - 如何将颜色输入到我不是以编程方式创建的 plist 中?