ios – 查询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)

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

<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时:谓词:是说:

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获取用户.

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...