Search results for

NSPersistentCloudKitContainer

589 results found

Post

Replies

Boosts

Views

Activity

Reply to WidgetKit and CoreData/CloudKit
Short Answer: You can't achieve Core Data / iCloud sync with NSPersistentCloudKitContainer in Widgets I ran many tests with and without WidgetKit and I discovered that no matter what I tried, I could never get NSPersistentCloudKitContainer to sync while an app is in the background. There is no amount of time that you can wait either, the sync will simply not happen. I tried querying Core Data during BackgroundTasks and the data is simply never there. I can see that a sync operation gets queued with a priority of 2 but only when an app becomes active does the sync even run. Widgets always run in the background. Since NSPersistentCloudKitContainer only runs while an app is in the foreground and since widgets only run in the background, the sync will never happen unless you launch the app. This isn't ideal because say you have the app installed on another device like a watch, your widget on your phone will never receive the updates that you do on the watch. At least, not with NSPersistentCloudKitContainer
Nov ’20
Reply to Shared NSPersistentCloudKitContainer
It seems like anywhere I read, it says the same thing: It Does Not. Before iOS14 NSPersistentCloudKitContainer only worked with Private Database iOS14 + NSPersistentCloudKitContainer works with Public & Private Databases Soo NSPersistentCloudKitContainer does not work with the Shared Database even if you use CKShare to share the underlying CKRecord object. The user can access the shared object and modify it but through CloudKit Apis and not via NSPersistentCloudKitContainer sync mechanism to CoreData. Also, I have red multiple responses by Apple Engineers, and no where they hinted that they are working on it, or that if it is something technically viable for the future. So at this point, I don't know what to do, since obviously using CKShareApi outside CoreData will require a huge amount of App rewrite. References: https://developer.apple.com/forums/search/?q=NSPersistentCloudKitContainer
Nov ’20
Shared NSPersistentCloudKitContainer
Given the current quarantine and self isolation around the world, I was wondering if NSPersistentCloudKitContainer can be shared between users for collaborative work - pretty much like Pages or Keynote. I am aware of the new .public database scope, but this would rather be private with specific access by invitation. Is anyone aware of how to implement that?
1
0
655
Nov ’20
Reply to Invalid Bundle ID for container
I found a solution for my case, so I'm posting to help anyone else with a similar setup. If you're sharing a CloudKit container across multiple apps (using different bundle IDs), apart from specifying the container identifier when initializing the container, you must set NSPersistentCloudKitcontainerOptions on the NSPersistentCloudKit container (this is in the AppDelegate if you selected the Use CloudKit option during project creation) as shown below: let container = NSPersistentCloudKitContainer(name: ModelName) guard let description = container.persistentStoreDescriptions.first else { tt fatalError(No container descriptions available) } description.cloudKitContainerOptions = NSPersistentCloudKitContainerOptions(containerIdentifier:iCloud.com.organization.ContainerName) container.persistentStoreDescriptions = [ description ] In your code, when you access the desired container, you use the same container ID as in the description above: let container = CKContainer(identifier: iCloud.com.organization.C
Nov ’20
NSPersistentCloudKitContainer reverts NSManagedObject subclass to old value
I have an app that uses NSPersistentCloudKitContainer to synchronise data with iCloud. Users reported occasional data loss after which I started debugging my implementation.Part of my app’s implementation is showing a pop-up that displays information and has a confirm button. When the user clicks this button, one or more instances of a custom NSManagedObject subclass gets modified.At the same time, NSPersistentCloudKitContainer triggers a mirror process when the app resigns and becomes active. This happens when the user clicks the above mentioned confirm button. It does this by executing a NSCloudKitMirroringExportRequest and NSCloudKitMirroringImportRequest request.In other words, in my app, data gets modified (explicitly via code) and gets mirrored (implicitly via CloudKit) at the same time, and this is where things go wrong.Essentially this is what happens:1. A property (NSTimeInterval) of an instance of an NSManagedObject subclass gets incremented (e.g. 0 + 1 = 1).2. NSPersistentCloudKitContainer
2
0
1.3k
Oct ’20
Many-to-one relationship can't be unlinked
I am using NSPersistentCloudKitContainer, and have a many-to-one optional relationship, let say many item to one project.This relationship is optional, so I can do this ->item.project = nilwhen the user decided that this item does not belongs to any project.This code is fine in Core Data, and the inverse relationships are updated accordingly.However, once this gets synced to CloudKit, and come back down, the project relationship will be restored. Setting the project to other entities are fine, it just cannot be set to nil.Playing with the CloudKit dashboard, I realized that the schema that is created have a CD_Project as String. If I create a new item without any project, there's no such field, however, once I assign a project to an item, the field is set, and there is no way to unset this field, even from the CloudKit Dashboard. I naively tried to clear out the string in cloudkit dashboard but it crashes my app when the sync happens.Is this a bug that will be fixed? The issue is also posted by an
3
0
1.4k
Oct ’20
Is it possible to rename Entities after using NSPersistentCloudKitContainer in Core Data?
I've tried using renaming Identifier: 1) Automatic / Lightweight migration seems to fail, because CloudKit integration forbids renaming entities. older devices cannot process these records 2) Tried using just NSPersistentContainer, and the lightweight migration still fails with the above message. NSPersistentCloudKitContainer seems to have marked/tainted the persistent store / SQLite so that renaming of entities is not possible at all. Does anyone know if it is possible to rename entities once you start using NSPersistentCloudKitContainer? (heavyweight migration or such?) Has anyone done this before, in a production app or otherwise?
1
0
1k
Oct ’20
How to add CloudKit to iOS with Watch Project (xcode 12/swift ui)
There isn't a signing capability for icloud that is available for either the app or watchos extension targets. My end goal is to have the CoreData CloudKit container that is used by both applications to be in sync and fetch / update the models they modify. Here is what I've done so far: Create iOS with watch app cookie cutter app with xcode 12 Add Remote Notification for Background Modes for both the iOS and watch extension targets. Note I CANNOT find anything to do with icloud or cloudkit as a capability to add. Add the persistence context to the iOS App @main struct MyApp: App { tt@Environment(.scenePhase) private var scenePhase tt@StateObject private var persistentStore = PersistentStore.shared ttvar body: some Scene { ttttWindowGroup { ttttttContentView() tttttttt.environment(.managedObjectContext, persistentStore.context) tttt}.onChange(of: scenePhase) { phase in ttttttswitch phase { ttttttcase .active: ttttttttprint(active) ttttttcase .inactive: ttttttttprint(inactive) ttttttcase .background: ttttttttpr
1
0
1.5k
Oct ’20
CoreData with CloudKit in WidgetKit not working
In my app, I have an NSPersistentCloudKitContainer set up in the following way: 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 } When I invoke a fetch request on the context of the container in my iOS target, it works as expected. However, when I perform the same fetch request in my Widget target, it returns an empty array result. In my iOS target, I have Background Modes / Remote Notifications and iCloud / CloudKit capabilities. In my Widget target, I have the iCloud / CloudKit capability. Not sure why it isn't working, so any help would be much appreciated, thanks!
3
0
1.1k
Sep ’20
How to debug NSPersistentCloudKitContainer background updates?
I have been using NSPersistentCloudKitContainer in my app for a while now. My main issue at the moment is that even though I have followed all of the documented steps for setting up background silent notifications, they don't seem to be working. (I query for the Core Data state from a Shortcut/Intent and can verify that the Core Data store hasn't been updated.) This hasn't been too much of an issue, but with new system features like widgets (WidgetKit), this is an issue I can no longer ignore. I'm not sure if it's completely out of my control (e.g. the OS just has decided not to deliver the notifications in the background) or if there's some undocumented step I need to take to ensure it is set up correctly. Has anyone gotten background syncing to work properly with NSPersistentCloudKitContainer? Did you have to do anything special to get it to work? Any tips for debugging what might be going wrong?
5
0
1.4k
Sep ’20
Update an Existing Xcode Project Core Data with CloudKit & Manage Multiple Stores
Hi, I have.a project that uses CoreData and I want to add some of the data to iCloud to sync with a Watch app and I ticked the option for the Default configuration to use iCloud and It worked but now I don't want to include images in the cloud because it became too large so I Seperated the images into a different data thing and as per instructions here https://developer.apple.com/documentation/coredata/mirroring_a_core_data_store_with_cloudkit/setting_up_core_data_with_cloudkit I added a configuration Local and Cloud and change the code as below - original lazy var persistentContainer: NSPersistentContainer = { ttlet container = NSPersistentContainer(name: DataModel) ttcontainer.loadPersistentStores(completionHandler: { ttttstoreDescription, error in ttttif let error = error { ttttttprint(Could load data store: (error)) tttt } tt}) ttprint(Loaded data store: DataModel) ttreturn container }() I created two configurations as per the video and ticked use with iCloud on the one I would like to sync with iCloud. n
1
0
1.5k
Aug ’21
NSSecureUnarchiveFromData is now necessary for transformable attributes but does not work with Core Data CloudKit?
On iOS 13 for transformable attributes that have no custom Transformer class set this appears in the console:One or more models in this application are using transformable properties with transformer names that are either unset, or set to NSKeyedUnarchiveFromDataTransformerName. Please switch to using NSSecureUnarchiveFromData or a subclass of NSSecureUnarchiveFromDataTransformer instead. At some point, Core Data will default to using NSSecureUnarchiveFromData when nil is specified, and transformable properties containing classes that do not support NSSecureCoding will become unreadable.This message appears on devices, in the simulator on High Sierra it even leads to a crash.However, setting the transformer class to NSSecureUnarchiveFromDataTransformer when using CoreData CloudKit, this crashes and leads to Core Data not being initialized.Disabling CloudKit, e.g. setting the .cloudKitContainerOptions on the store description to nil fixes this crash.It seems CoreData CloudKit does not support NSSecureCoding tr
11
0
15k
Sep ’20