swift - 将 cloudkit 与 coredata 一起使用时,模拟器和真实设备永远不会相互同步
问题描述
我使用核心数据作为本地存储,使用 Cloudkit 作为后端来托管我的 iOS 应用程序。我使用 NSPersistentCloudKitContainer 与 Coredata + Cloudkit 一起工作。
这就是代码的样子
struct UserProfile {
static let shared = UserProfile.init()
let container: NSPersistentCloudKitContainer
init() {
container = NSPersistentCloudKitContainer.init(name: "Profile")
guard let description = container.persistentStoreDescriptions.first else {
fatalError("Unable to retrieve a persistent store description")
}
description.setOption(true as NSNumber, forKey: NSPersistentHistoryTrackingKey)
description.setOption(true as NSNumber, forKey: NSPersistentStoreRemoteChangeNotificationPostOptionKey)
container.loadPersistentStores { storeDescription, error in
if let error = error as NSError? {
fatalError("Unable to load todo:\(error)")
}
}
container.viewContext.automaticallyMergesChangesFromParent = true
container.viewContext.mergePolicy = NSMergeByPropertyObjectTrumpMergePolicy
}
}
在保存数据之前,我确保模拟器有一个 icloud 帐户。到目前为止,我已经测试过数据已与具有相同帐户的多个模拟器成功同步。
但是当我用真实设备测试模拟器时,反之亦然。它不会相互同步,就好像两者都被视为不同的设备一样。(两者拥有相同的帐户)
我确保一切都已相应设置:
- 两种设备具有相同的构建
- 后台远程通知已打开
- 模拟器和真机具有相同的 icloud 帐户
- coredata 中的所有属性都是可选的,除了 1-2 字段是必需的,所以不确定同步问题是否是由于架构相关问题引起的?(我的意思是我已经在 xcode 中更新了几次架构)
- 模拟器完美同步
- 我已经阅读了一些 stackoverflow,但找不到特定于我的用例的问题。
任何帮助表示赞赏
更新:比较是通过模拟器上的应用程序和从 testflight 下载的应用程序进行的。两者都有相同的 icloud 帐户。
解决方案
推荐阅读
- javascript - Ajax - 根据返回值更改文本颜色
- python - 在 PutFile 之后执行 Python 脚本(Apache - NiFi)
- python - 去重记录(窗口函数熊猫)
- docker - Makefile 使用不同的选项同时多次运行相同的目标
- javascript - 为 Miller-Rabin 测试创建一个随机 BigInt
- numpy - 有人可以解释这种 numpy 切片行为吗?
- php - 我如何存储用户输入信息并使用 php 存储到管理页面
- typescript - 对 Typescript 函数返回类型感到困惑
- github - 是否有任何自动方式从 GitHub 存储库填充 Moodle 培训?
- python - tfp.optimizer.lbfgs_minimize() 无法识别 previous_optimizer_results 参数