mum*_*ush 4 core-data cloudkit swiftui ios14
我的应用程序是用 SwiftUI 编写的,使用 Cloudkit 来存储核心数据中的记录。我能够获取用于@FetchRequest填充列表的记录。现在我想获取当前用户的 iCloud ID 并将其与另一个全局 ID 进行比较,但我遇到了问题fetchUserRecordID...
查看 Cloudkit Dashboard 的记录类型时,我可以看到用户记录Users。但每次运行下面的代码时,我都会收到以下错误:“无法从容器“iCloud.com.my_container_name”的服务器获取容器配置”
我正在运行 Xcode 12.2 Beta 4
ContentView.swift
struct ContentView: View {
@Environment(\.managedObjectContext) private var viewContext
init() {
isCreator()
}
var body: some View {
Text("Hello World")
}
func isCreator() {
CKContainer.default().fetchUserRecordID(completionHandler: { (recordId, error) in
guard let record = recordId, error == nil else {
print("Error: \(error!.localizedDescription)")
return
}
print("Found record")
// Now do something with record...
})
}
} // end ContentView
Run Code Online (Sandbox Code Playgroud)
使用CKContainer(identifier: "iCloud.name_of_your_container")而不是CKContainer.default()
我的问题是我命名了我的 Cloudkit 容器testapp,而我的应用程序的捆绑 ID 是com.my_team_name.testapp。运行 Cloudkit 查询时,我不断收到此错误:
Couldn't get container configuration from the server for container "iCloud.com.my_team_name.testapp"
查看 Cloudkit 仪表板后,我意识到我的容器名称实际上只是“testapp”。
一旦我将代码更改为CKContainer(identifier: "iCloud.testapp"),它就工作得很好。
| 归档时间: |
|
| 查看次数: |
917 次 |
| 最近记录: |