【问题标题】:fetchUserRecordID Cloudkit error: Couldn't get container configurationfetchUserRecordID Cloudkit 错误:无法获取容器配置
【发布时间】:2020-11-14 01:21:59
【问题描述】:

我的应用是用 SwiftUI 编写的,使用 Cloudkit 来存储来自 Core Data 的记录。我可以使用@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

【问题讨论】:

    标签: core-data swiftui cloudkit ios14


    【解决方案1】:

    使用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"),它就可以正常工作了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-11-03
      • 1970-01-01
      • 2021-11-01
      • 2021-08-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多