I am trying to build a widget for iOS 14 using WidgetKit and CoreData/CloudKit instance on a new Xcode 12 project. I have added my CoreData's File Target Membership to both my app and widget I have added an App Group to my main App Target. My Persistence.swift looks like this: init(inMemory: Bool = false) { container = NSPersistentCloudKitContainer(name: test-cd) let storeURL = URL.storeURL(for: group.test-data, databaseName: test-cd) let storeDescription = NSPersistentStoreDescription(url: storeURL) container.persistentStoreDescriptions = [storeDescription] 4. My widget looks like this: struct Provider: TimelineProvider { var managedObjectContext : NSManagedObjectContext init(context : NSManagedObjectContext) { self.managedObjectContext = context } ... } @main struct test_widget: Widget { let kind: String = test_widget var persistentContainer = PersistenceController.shared.container var body: some WidgetConfiguration { StaticConfiguration(kind: kind, provider: Provider(context: persistentContainer.v
Search results for
NSPersistentCloudKitContainer
589 results found
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
I am using the new iOS 13 NSPersistentCloudKitContainer for Syncing CoreData with iCloud.For large size binary data i am using Allow External Storage in Core Data Model.• I successfully added 200MB sized video on one device.• It got synced to iCloud successfully.• On the other device, when i am opening the App, it is receiving the CloudKit record, but somehow not able to work properly.There is no programming error from my end. I have made sure that in CoreData Model Allow External Storage is selected. Looks like it has something to do with how NSPersistentCloudKitContainer imports the large binary data.Errorerror: SQLCore dispatchRequest: exception handling request: <NSSQLSaveChangesRequestContext: 0x2805386c0> , *** NSAllocateMemoryPages(227428466) failed with userInfo of (null)CoreData: error: SQLCore dispatchRequest: exception handling request: <NSSQLSaveChangesRequestContext: 0x2805386c0> , *** NSAllocateMemoryPages(227428466) failed with userInfo of (null)2020-01-18 20:52:24
If you Changed the name of your .xcdatamodel file ensure that the same name you changed it to is used when making your container in AppDelegate.swift as below let container = NSPersistentCloudKitContainer(name: Same Name )
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags:
I am using Core Data with CloudKit through NSPersistentCloudKitContainer. When doing the following, all the data disappears: Start my app (iCloud enabled) Create some items in CoreData Quit the app Turn off iCloud for my app in the iPhone's Settings Start the app again All the items added in step 2 are gone after this. When I turn iCloud on again, they reappear. I read through the documentation, but this does not seem to be expected behaviour. Also, the demo app - https://developer.apple.com/documentation/coredata/synchronizing_a_local_store_to_the_cloud for this topic does not seem to have this issue. However, I am building my CoreData-stack in the same way as they do. Searching on the web it seems that several people have the same issue. Did somebody resolve this? I read that one strategy is to swap NSPersistentCloudKitContainer with NSPersistentContainer in case iCloud is turned off - but the demo-app doesn't do this and still keeps the data even when iCloud gets turned off. So there must
Topic:
App & System Services
SubTopic:
iCloud & Data
Tags:
CloudKit
Core Data
Cloud and Local Storage
Can we access NSPersistentCloudKitContainer in the same way we do from the app, or will we need still need App Groups? I don't think CloudKit containers work with App Groups.
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags:
The callback from syncing of NSPersistentCloudKitContainer is mostly added from iOS14 onwards. I got to know that NSPersistentCloudKitContainer.Event helps to understand sync status of data from CoreData to CloudKit. Use Case: I need to understand the sync status of data from watch to Cloudkit, so that I can choose to send it explicitly to companion phone or not. Has anybody got leads how to use make use of the newly released features forNSPersistentCloudKitContainer in iOS14? For reference : [https://developer.apple.com/documentation/coredata/nspersistentcloudkitcontainer)
In the previous version of my app, I used this pattern for previews that depended on a NSManagedObjectContext: struct ContentView_Previews: PreviewProvider { static var previews: some View { tttt let managedObjectContext = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext return ContentView().environment(.managedObjectContext, managedObjectContext) } } With the delegate gone, I've swapped to this: class PreviewData { static var persistentContainer: NSPersistentContainer = { let container = NSPersistentCloudKitContainer(name: Structure) container.loadPersistentStores(completionHandler: { _, error in if let error = error { fatalError(Unresolved error (error)) } }) return container }() static var previewContext: NSManagedObjectContext { persistentContainer.viewContext } This works for previews some of the time. For example, I have this FilteredList: import CoreData import SwiftUI protocol StructureManagedObject { static var defaultSortDescriptors: [NSSortDescriptor] { get }
Hi there! I built an app using Core Data and CloudKit using NSPersistentCloudKitContainer - https://developer.apple.com/documentation/coredata/nspersistentcloudkitcontainer. However, now that I'm looking to add support for extensions, I need to migrate the existing store from its default location using migratePersistentStore(_:to:options:withType:) - https://developer.apple.com/documentation/coredata/nspersistentstorecoordinator/1468927-migratepersistentstore so it can be accessed from a new App Group. Once I update the app to the new build with the migration logic, the store appears empty to CloudKit and the existing objects are re-downloaded to the device. This effectively duplicates all of the records. It seems as though the migrated records are new NSManagedObjects, which would explain why CloudKit doesn't have a corresponding CKRecord. Upon detecting that the CloudKit version of the object does not exist on device, NSPersistentCloudKitContainer ensures that it is created (appea
One question I often see on DevForums and in my day DTS job is if a Core Data object managed by NSPersistentCloudKitContainer can be shared with other iCloud users. The answer is yes but you need to do it using CloudKit API directly because NSPersistentCloudKitContainer doesn’t support CloudKit shared database (CKContainer.sharedCloudDatabase) today. Assuming you have a Core Data object, let’s say a document, that you’d like to collaborate with your colleagues: You are the document owner and can use NSPersistentCloudKitContainer to fully manages the document and synchronize it across your devices. You can grab a CloudKit record associated with your document from NSPersistentCloudKitContainer using record(for:) or recordID(for:), and share it to your colleagues using UICloudSharingController. See our Sharing CloudKit Data with Other iCloud Users - https://developer.apple.com/documentation/cloudkit/sharing_cloudkit_data_with_other_icloud_users sample for how to share a CloudK
I am currently testing the NSPersistentCloudKitContainer. I have strictly followed the guidelines of the new documentation. Basically everything works as desired. I use the option NSPersistentStoreRemoteChangeNotificationPostOptionKey on the description to receive Updates from the remote data store. But the updates from the remote database are only delivered if the app is in the foreground. But I would like to update my widget based on a data change in the backend. Does anyone has an idea how to solve this issues? What i did so far: Background Modes in Capabilities are enabled Push Notifications are enabled i called registerForRemoteNotifications HistoryTracking and RemoteChange Option are enabled on the description of the PersistentStore Syncing works in foreground ✅ Syncing does not work if App is in Background ❌ forKey: NSPersistentStoreRemoteChangeNotificationPostOptionKey) description?.setOption(true as NSNumber, forKey: NSPersistentHistoryTrackingKey) container.viewContext.automaticallyMergesCh
I have the same question. I haven't been able to see any source explicitly state that NSPersistentCloudKitContainer sets the app to update its db while it is in the background, so I am starting to doubt it is even possible.
Topic:
App & System Services
SubTopic:
iCloud & Data
Tags:
Hi thank you for making this post. This is really helpful. I have a follow up. There is a 5th point that is missing. What happens when the owner modifies something in the shared document. The other participant can't use private database auto synced with NSPersistentCloudKitContainer because they must use CKContainer.sharedCloudDatabase for shared documents. How to I manually fetch the changes in real time reliability? I saw Maintain a Local Cache For CloudKit Records described here https://developer.apple.com/documentation/cloudkit/sharing_cloudkit_data_with_other_icloud_users but do not understand it. Could you please describe in simpler steps to keep the CKContainer.sharedCloudDatabase synced in real time. Thank you 🙏
Topic:
App & System Services
SubTopic:
iCloud & Data
Tags:
I use NSPersistentCloudKitContainer to sync my apps data to iCloud. The app has a settings switch to enable or disable iCloud sync. As described in this thread, - https://developer.apple.com/forums/thread/118924 I set cloudKitContainerOptions to nil depending on the users setting. This is done before the persistent stores are loaded and works fine when the app is launched for the first time. My problem is that I don't know how to apply this settings change while NSPersistentCloudKitContainer is already loaded and active and its ManagedObjectContexts are in use? I could reload the entire container, but will that work while the app is still using contexts from the other container?
I've posted a suggestion for a sync enabled/disabled switch on NSPersistentCloudKitContainer through the feedback tool (FB8571301). This is the reply I got: We do not encourage applications to implement their own sync controls. The user can control the sync state of an application using the iCloud Preferences in the Settings app. The problem is that the iCloud preferences in the settings app are rather hidden.. And there is no way to directly link to this page from my app. There are inherent ownership challenges with toggling between synced and unsynced data. For this reason we recommend using a separate persistent store to hold unsynced data separately from the user’s iCloud data. This is necessarily a heavy-weight operation, the local store must be added and the cloud store removed when the user disables sync. You can customize the persistent store descriptions of a container after it is initialized. For example, you can set the store descriptions on it immediately, which will prevent the default d
Topic:
App & System Services
SubTopic:
iCloud & Data
Tags:
> Then I'd say it's safe to just keep hitting CloudKit with the same request until it succeeds, keeping any additional errors silenced. Here I see that you are able to listen if quota is exceeded or if the sync is successful or not. Is it a manual sync you are doing to the CloudKit or is the container configured as NSPersistentCloudKitContainer? If it is the later, how are you able to listen to these status callbacks? Any leads would be appreciated. TIA
Topic:
App & System Services
SubTopic:
iCloud & Data
Tags: