gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-10-30 22:07:41 27 4
gpt4 key购买 nike

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

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com