ios - 如何在仅从远程 CloudKit 数据库收到更改时收到通知?
问题描述
我正在使用 Core Data 和 CloudKit 构建一个应用程序。我需要检测远程更改何时被推送到应用程序并且在本地数据库中可用以对新数据集执行一些工作。我已经.NSPersistentStoreRemoteChange
这样实现了:
NotificationCenter.default.addObserver(self, selector: #selector(self.storeRemoteChange(_:)), name: .NSPersistentStoreRemoteChange, object: container.persistentStoreCoordinator)
问题是即使没有从远程 CloudKit 数据库收到更改也会收到此通知,例如启动应用程序 4 次,以及对本地数据库进行修改时。我如何才能知道何时从远程数据库收到更改?
解决方案
虽然我无法仅检测到这种情况,但我确实通过NSManagedObjectContextObjectsDidChangeNotification
在触发此通知时利用并执行远程和本地更改处理来满足我的需求。
推荐阅读
- c - “返回类型”是标签的函数有什么作用?
- javascript - 最接近的数字,基于两个数字
- linux - 在 Linux (Ubuntu WSL) 上通过 CLISP 运行 LISP 代码
- java - 在java8中过滤布尔值
- oracle - Oracle根据总和从查询集中删除行
- python - 按下按键时pygame继续循环
- spring-boot - Springboot 2.3 docker镜像构建两个镜像
- xamarin - 嵌入式 Vimeo 视频未在 xamarin android 中显示全屏按钮
- python - wxFormBuilder 组件类最小化
- typeorm - 使用“getRepository()”构建类的最佳方法 - Typeorm w/ Type-Graphql