ios - WidgetKit中带有CloudKit的CoreData不起作用
问题描述
在我的应用程序中,我NSPersistentCloudKitContainer
通过以下方式进行了设置:
let container: NSPersistentCloudKitContainer
init() {
self.container = NSPersistentCloudKitContainer(name: "Model")
self.container.persistentStoreDescriptions[0].setOption(
true as NSNumber,
forKey: NSPersistentStoreRemoteChangeNotificationPostOptionKey
}
self.container.loadPersistentStores { (_, error) in
guard error == nil else {
print("error loading store: \(error.debugDescription)")
return
}
}
self.container.viewContext.automaticallyMergesChangesFromParent = true
}
当我在我的 iOS 目标中对容器的上下文调用 fetch 请求时,它按预期工作。但是,当我在 Widget 目标中执行相同的 fetch 请求时,它会返回一个空数组结果。
在我的 iOS 目标中,我有后台模式/远程通知和 iCloud/CloudKit 功能。在我的 Widget 目标中,我具有 iCloud / CloudKit 功能。
不知道为什么它不起作用,所以任何帮助将不胜感激,谢谢!
解决方案
推荐阅读
- python - Python Selenium Webdriver 在“data-original-title”中获取文本
- c# - 封装业务决策 - 如何返回它们
- django - 在django中将UTC时间转换为本地时间
- javascript - 如何将“添加文档”移动到库顶部?
- java - 如何在没有“未经检查”警告的情况下转换为(已知)泛型类型?
- xslt-3.0 - 如何使用 xslt 3.0 通过 try/catch 处理错误异常
- java - 无法在 bpmn 图上画图
- python - 检查数据框组是否包含列表中的值
- php - 如何延迟 php 脚本的执行时间,以便 python 脚本可以完成
- excel - 循环遍历 Excel 中的行和列