I'm adding iCloud sync using NSPersistentCloudKitContainer to my production app. When the user firsts downloads the app, they are prompted to create a profile (they basically just choose an icon representing something). There's no email address or anything, and the user can create multiple profiles to track different things. Now that there's iCloud sync, if a user downloads the app on an iPad after using it on their phone, they are still prompted to create a profile. There's no way around this as far as I can tell, because you cannot manually trigger a sync and it sometimes takes a full 5 minutes for NSPersistentCloudKitContainer to decide to sync. How do I handle the UX of this? I don't want the user to have to create a new profile and then delete/merge it once the data comes in, but I can't rely on iCloud syncing in time to handle this case. Any advice would be really appreciated.
Search results for
NSPersistentCloudKitContainer
589 results found
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
I called NSPersistentCloudKitContainer multiple times in a controller, and the same problem occurred. After modifying the code, the instance was created only once, and then called multiple times, the problem was solved.
Topic:
App & System Services
SubTopic:
iCloud & Data
Tags:
I'm struggling to initialize my schema. I keep getting the error : Error Domain=NSCocoaErrorDomain Code=134060 A Core Data error occurred. UserInfo={NSLocalizedFailureReason=Couldn't initialize CloudKit schema because no stores in the coordinator are configured to use CloudKit Without the initialize it does sometimes create the record's schema. But it feels like its all half working. I have Cloudkit on and Used with Cloudkit is checked under the default configuration in my xcdatamodeld file. Here is my setup code.. _persistentContainer = [[NSPersistentCloudKitContainer alloc] initWithName:@Eco-nomy]; // Add options and make this container PUBLIC. NSPersistentStoreDescription *description = _persistentContainer.persistentStoreDescriptions.firstObject; [description setOption:[NSNumber numberWithBool:YES] forKey:NSPersistentHistoryTrackingKey]; [description setOption:[NSNumber numberWithBool:YES] forKey:NSPersistentStoreRemoteChangeNotificationPostOptionKey]; description.cloudKitContainerOptions.databas
I'm using NSPersistentCloudKitContainer to sync my Core Data stack with iCloud. I have one model that I want to be local to the device - how would I exclude that model from being synced while making sure it is saved to the device?
I'm using Core Data and NSPersistentCloudKitContainer to sync the data using iCloud. There is some data that I want to just be local to the device, how would I make a CoreData model that is not synced with the cloud?
Hi all, I'm trying to use NSPersistentCloudKitContainer.initializeCloudKitSchema() to initialise a public CloudKit database, but it seems to fail when any given entity has more than two String fields (or, it seems, any two fields which NSPersistentCloudKitContainer decides need to be CKAsset-backed). I've raised rdar://FB8995024 about this too, but was wondering if someone here can see something I'm missing. I can consistently reproduce this on iOS 14.4 (18D46) on the iOS Simulator with Xcode 12.4 (12D4e), or with an iPhone 11 Pro running iOS 14.4 (18D52) using this code (in a new iOS App project, SwiftUI/SwiftUI App/Swift, Use Core Data+Host in CloudKit) and a single Core Data entity with two String attributes: import CoreData import SwiftUI @main struct NSPersistentCloudKitContainer_initTestingApp: App { let persistenceController = PersistenceController.shared var body: some Scene { WindowGroup { Text(Success) } } } struct PersistenceController { static let shared = PersistenceController() let cont
Topic:
App & System Services
SubTopic:
iCloud & Data
Tags:
CloudKit
Core Data
Cloud and Local Storage
I am transitioning to using CloudKit for syncing, using NSPersistentCloudKitContainer to manage syncing. In my app you can record audio, and I've been saving that by saving the file to disc and storing a relative URL to Core Data. How can I get this to work using NSPersistentCloudKitContainer? I read that I shouldn't store large data as a CoreData attribute for performance, but I need the data to sync with CloudKit.
Hi, I am designing a simple task manager for a household in SwiftUI. I would like the app to synchronise the content data across the devices of the various users part of the household. To me, this seems like a simple enough process potentially. Which approach is best suitable with the SwiftUI framework? The data model of the app is very simple at the moment; essentially a collection of tasks that each feature a title, description and assignment to a user. Running the app locally, without synchronisation implemented yet, allows me to make use of the SwiftUI's framework declarative programming and elegant design. I realise that to implement synchronisation with other users' devices unavoidably means I need to implement code and adapt existing code. For years, I have browsed articles and tutorials on data sharing in iOS apps. Options I have explored are Core Data, CloudKit, manual API fetching from server and third-party options like Realm. The underlying, unnamed issue seems to be that SwiftUI is still young an
I am trying to save to Core Data so when the App is reopened the data will be there. I have a single ViewController, within that VC I have 10 Text Fields which the user inputs their data (numbers). I have a function where I add all the data for the 7 days (sun - sat) and it shows the total value. I have most in place (xcdatamodeld)... Is it possible to have CoreData fill text fields? Is there a good tutorial on completing core data? Most I have read and watched all use table views for the example.What I want to do is have the same data show up after closing and re-opening the App. // MARK: - Core Data stack lazy var persistentContainer: NSPersistentCloudKitContainer = { let container = NSPersistentCloudKitContainer(name: Numbers) container.loadPersistentStores(completionHandler: { (storeDescription, error) in if let error = error as NSError? { // Replace this implementation with code to handle the error appropriately. // fatalError() causes the application to generate a crash log and termina
My app uses NSPersistentCloudKitContainer to sync Core Data objects among users' devices, and has been doing so successfully for about a year now. My issue is I can't find any way to debug when I have a specific user that is experiencing sync issues. I have had the user try every trick that I know of to resolve it but have had no luck. I have tried everything in the CloudKit dashboard, but no logs appear whatsoever. Anyone have any tips here?
When I sync my large Core Data database with NSPersistentCloudKitContainer, inserting new rows works well for up to 10k rows. (in batches of ~400 inserts) After that, CloudKit receives a 503 Service Unavailable error with a timeout. Here's the log: CoreData: CloudKit: CoreData+CloudKit: -[PFCloudKitExporter exportIfNecessary]_block_invoke_2(153): : Found 22161 objects needing export. 2021-01-14 11:26:54.985447+0100 [1299:350390] [error] error: CoreData+CloudKit: -[NSCloudKitMirroringDelegate _exportFinishedWithResult:exporter:](1163): : Export failed with error: The API documentation - https://developer.apple.com/library/archive/documentation/DataManagement/Conceptual/CloudKitWebServicesReference/ErrorCodes.html#//apple_ref/doc/uid/TP40015240-CH4-SW1 says 503 means interal server error (try again later) and also says that for throttling the status code would be 429, so I guess it's not rate limiting? I only found that there is a rate limit of 40 requests/second, but since CoreData is doing batch ins
Topic:
App & System Services
SubTopic:
iCloud & Data
Tags:
CloudKit
Core Data
Cloud and Local Storage
Hi I have an app that runs on iOS and MacOS (actually they are separate apps) and Core Data from a NSPersistentContainer, is synced with iCloud using a custom solution utilising pre-NSPersistentCloudKitContainer CloudKit methods. I would like to migrate that solution to NSPersistentCloudKitContainer but am having trouble figuring out how to do it and whether it's even possible. In particular, as I cannot guarantee that all devices would migrate at the same time, there would need to be a period where both synchronisation methods are active. Moreover, they would need to be active on one device, which would need to act as some sort of translator between the two methods. Then, it would be quite hard to determine when to stop using and delete old records from the cloud as that would have to be done from the last device to migrate. And that would be quite hard to determine from the app. Finally, as each device has its own Core Data objectIDs all managed objects would end up being duplicated in iCl
The app uses Core Data + CloudKit. When the app gets launched WidgetKit file fetches correct entries from Core Data but when I add new entries to Core Data from the main app and call WidgetCenter.shared.reloadTimelines() updated entries don't get fetched and old data is displayed inside the widget. Main app and Widget target have the same App group, iCloud capability enabled for both targets. When I call WidgetCenter.shared.reloadTimelines() from the Main app Widget reloads (timer added to Widget view sets to zero) but fetch from Core Data doesn't return newly added entries. Then I restart the app and correct entries get fetched. Why doesn't it fetch correct entries when WidgetCenter.shared.reloadTimelines() gets called and only works when app is relaunched? Widget's code: import WidgetKit import SwiftUI import CoreData struct Provider: TimelineProvider { ttfunc placeholder(in context: Context) -> HabitsEntry { ttttHabitsEntry(date: Date(), habitsCount: 0) tt} ttfunc getSnapshot(in context: Context, comple
I've added iCloud into my SwiftUI app and everything seems to be working great, however I need to implement an on off toggle for it. After searching, I found a couple forums posts that suggested to re-create the container when icloud is toggled on off. Here's the code: lazy var persistentContainer: NSPersistentContainer = { ttreturn setupContainer() }() /* This is called when the iCloud setting is turned on and off */ func refreshCoreDataContainer() { tt/* Save changes before reloading */ tttry? self.persistentContainer.viewContext.save() tt/* Reload the container */ ttself.persistentContainer = self.setupContainer() } private func setupContainer() -> NSPersistentContainer { ttlet useCloudSync = UserSettings.shared.enableiCloudSync ttlet container: NSPersistentContainer! tt/* Use the icloud container if the user enables icloud, otherwise use the regular container */ ttif useCloudSync { ttttcontainer = NSPersistentCloudKitContainer(name: App) tt} else { ttttcontainer = NSPersistentContainer(name: A
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
Topic:
App & System Services
SubTopic:
iCloud & Data
Tags: