好的,所以我在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.