查询CloudKit用户记录给出了“不能查询系统类型”。 [英] Querying CloudKit Users Record gives "Can't query system types"

查看:132
本文介绍了查询CloudKit用户记录给出了“不能查询系统类型”。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Okay, so I'm building a game on top of CloudKit and I want to query the users with the top 50 scores for a leaderboard.

// 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)

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

This does not add any records to the records array and it comes back with this error in the completion 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的文档中找到了答案。特别是

I found the answer to this one in Apple's docs. Specifically the docs on CKQueries.

在有关 initWithRecordType:predicate:的讨论中:


您无法查询用户记录,并且无法执行将记录类型设置为CKRecordTypeUserRecord的查询会导致错误。您必须直接使用其ID来获取用户记录。

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不允许您查询用户记录。

So I guess CloudKit doesn't let you query User records.

我最终添加了一个分数记录并参考了用户。我问了一下,然后就可以通过用户的ID来获取用户。

I ended up adding a score record with a reference to the users. I queried that and then I could get the users by their ID.

这篇关于查询CloudKit用户记录给出了“不能查询系统类型”。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆