相关疑难解决方法(0)

在不影响CloudKit正确性的情况下执行持久历史记录清除的正确方法是什么?

目前,我们正在使用本地CoreData功能CloudKit,通过使用NSPersistentCloudKitContainer.

为什么我们启用持久历史跟踪功能?

由于/sf/answers/5078817971/中描述的问题,我们需要启用NSPersistentHistoryTrackingKey.


清除历史记录

基于https://developer.apple.com/documentation/coredata/consuming_relevant_store_changes,我们应该手动执行持久历史记录清除。


但是,目前尚不完全清楚我们如何以安全的方式清除历史记录,而不影响 的正确性CloudKit。我们倾向于使用以下设置运行一些测试。

  1. 运行模拟器。我们将在模拟器中执行插入操作
  2. 运行真实设备。由于步骤 1,真实设备将收到静默推送通知。
  3. 模拟器和真实设备都运行相同的代码。
  4. 每当我们在模拟器中插入一个项目时,我们都会观察真实设备中发生的情况。

测试1:处理后立即清除所有历史数据

@objc func storeRemoteChange(_ notification: Notification) {
    // Process persistent history to merge changes from other coordinators.
    historyQueue.addOperation {
        self.processPersistentHistory()
    }
}

/**
 Process persistent history, posting any relevant transactions to the current view.
 */
private func processPersistentHistory() {
    backgroundContext.performAndWait {
        
        // Fetch history received from outside the app since the last token
        let …
Run Code Online (Sandbox Code Playgroud)

core-data ios swift cloudkit

8
推荐指数
1
解决办法
890
查看次数

标签 统计

cloudkit ×1

core-data ×1

ios ×1

swift ×1