我可以通过点击共享生成的链接生成共享并正常获取,但只要我关闭应用并再次打开它,它就全部消失了!我想要做的是在没有链接的情况下访问共享...通过打开应用程序,将内容加载到第一次已经接受的共享中。有人知道怎么做吗?
提前致谢
答案 0 :(得分:1)
我明白了!首先,您需要获取所需分享的CKRecordZone。
let sharedData = CKContainer.default().sharedCloudDatabase
sharedData.fetchAllRecordZones { (recordZone, error) in
if error != nil {
print(error?.localizedDescription)
}
if let recordZones = recordZone {
//Here you'll have an array of CKRecordZone that is in your SharedDB
}
}
现在,您只需要像常规CKRecord一样获取CKShare:
func asdasdasa(id: CKRecordZoneID) {
ctUsers = [CKRecord]()
let sharedData = CKContainer.default().sharedCloudDatabase
let predicate = NSPredicate(format: "TRUEPREDICATE")
let query = CKQuery(recordType: "Elder", predicate: predicate)
sharedData.perform(query, inZoneWith: id) { results, error in
if let error = error {
DispatchQueue.main.async {
print("Cloud Query Error - Fetch Establishments: \(error)")
}
return
}
if let users = results {
print(results)
self.ctUsers = users
print("How many shares in cloud: \(self.ctUsers.count)")
if self.ctUsers.count != 0 {
// Here you'll your Shared CKRecords!
}
else {
print("No shares found")
}
}
}
}