From 15a0fd849881f31881431e46659f25e5ece83984 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Franc=CC=A7ois=20Hamel?= Date: Sat, 14 Dec 2019 19:10:50 -0500 Subject: [PATCH 1/3] Added enable(persistentContainer container: NSPersistentContainer, withPull: Bool) to allow developer to specify if Pull should be performed on enable. --- Source/Classes/CloudCore.swift | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Source/Classes/CloudCore.swift b/Source/Classes/CloudCore.swift index a35a6c56..64aa392f 100644 --- a/Source/Classes/CloudCore.swift +++ b/Source/Classes/CloudCore.swift @@ -83,8 +83,9 @@ open class CloudCore { /// Enable CloudKit and Core Data synchronization /// /// - Parameters: - /// - container: `NSPersistentContainer` that will be used to save data - public static func enable(persistentContainer container: NSPersistentContainer) { + /// - container: `NSPersistentContainer` that will be used to save data + /// - withPull: `Bool` to specify if Pull shoul dbe perfromed or not on enable + public static func enable(persistentContainer container: NSPersistentContainer, withPull: Bool) { // Listen for local changes let observer = CoreDataObserver(container: container) observer.delegate = self.delegate @@ -98,6 +99,10 @@ open class CloudCore { queue.addOperation(subscribeOperation) #endif + if !withPull { + return + } + // Fetch updated data (e.g. push notifications weren't received) let updateFromCloudOperation = PullOperation(persistentContainer: container) updateFromCloudOperation.errorBlock = { @@ -110,6 +115,10 @@ open class CloudCore { queue.addOperation(updateFromCloudOperation) } + + public static func enable(persistentContainer container: NSPersistentContainer) { + self.enable(persistentContainer: container, withPull: true) + } /// Disables synchronization (push notifications won't be sent also) public static func disable() { From c6005376847f9bc261c4142a798ecce8e9ec8840 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Franc=CC=A7ois=20Hamel?= Date: Tue, 17 Dec 2019 20:06:04 -0500 Subject: [PATCH 2/3] Added public init() {} to CloudCoreConfig to allow intentiation of CloudCoreConfig. --- Source/Model/CloudCoreConfig.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Source/Model/CloudCoreConfig.swift b/Source/Model/CloudCoreConfig.swift index 3e96b043..034afccf 100644 --- a/Source/Model/CloudCoreConfig.swift +++ b/Source/Model/CloudCoreConfig.swift @@ -26,6 +26,8 @@ import CloudKit public struct CloudCoreConfig { // MARK: CloudKit + + public init() {} /// The CKContainer to store CoreData. Set this to a custom container to /// support sharing data between multiple apps in an App Group (e.g. iOS and macOS). From 4a264e06407121d7a1fb29253665cc618923bfb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Franc=CC=A7ois=20Hamel?= Date: Sat, 28 Dec 2019 09:15:00 -0500 Subject: [PATCH 3/3] cloudkit.share records must not be processed. --- .../Pull/SubOperations/RecordToCoreDataOperation.swift | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Source/Classes/Pull/SubOperations/RecordToCoreDataOperation.swift b/Source/Classes/Pull/SubOperations/RecordToCoreDataOperation.swift index 10001414..f58552ee 100644 --- a/Source/Classes/Pull/SubOperations/RecordToCoreDataOperation.swift +++ b/Source/Classes/Pull/SubOperations/RecordToCoreDataOperation.swift @@ -52,6 +52,10 @@ public class RecordToCoreDataOperation: AsynchronousOperation { private func setManagedObject(in context: NSManagedObjectContext) throws { let entityName = record.recordType + /// cloudkit.share records are generated by CloudKit when records are shared. + /// No need to get them in Core Data entities. + if entityName == "cloudkit.share" {return} + guard let entity = NSEntityDescription.entity(forEntityName: entityName, in: context) else { throw CloudCoreError.coreData("Unable to find entity specified in CKRecord: " + entityName) }