Search results for

NSPersistentCloudKitContainer

589 results found

Post

Replies

Boosts

Views

Activity

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
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
CoreData+CloudKit custom Zone
Hi, I'm using CoreData+CloudKit in a blank universal project for macOS 11 and iOS14. The records are in a private database inside a custom zone, I was able to set the correct database, but I'm yet to be able to set the zone. On the PersistentController created by default by Xcode 12 I have the following code let container: NSPersistentCloudKitContainer init(inMemory: Bool = false) { container = NSPersistentCloudKitContainer(name: finances_manager_pro) let customZone = CKRecordZone(zoneName: CloudCore) guard let description = container.persistentStoreDescriptions.first else { fatalError(Error) } description.cloudKitContainerOptions?.databaseScope = .private if inMemory { container.persistentStoreDescriptions.first!.url = URL(fileURLWithPath: /dev/null) } container.loadPersistentStores(completionHandler: { (storeDescription, error) in if let error = error as NSError? { fatalError(Unresolved error (error), (error.userInfo)) } }) } And inside a View @FetchRequest( sortDescriptors: [NSSortDescrip
2
0
1.9k
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
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
Implementing an iCloud on off button in SwiftUI results in crash
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
0
0
1.1k
Nov ’20
WidgetKit doesn't fetch updated data from Core Data when WidgetCenter.shared.reloadAllTimelines() gets called
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
3
0
2.9k
Nov ’20
Migration of a Custom Core Data CloudKit Sync to NSPersistentCloudKitContainer
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
0
0
697
Dec ’20
NSPersistentCloudKitContainer - CloudKit Error 503 after inserting batch of elements
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
0
0
690
Jan ’21
How to debug Core Data iCloud sync issue in production?
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?
1
0
1.1k
Jan ’21
Saving and fetching to Core Data
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
1
0
830
Feb ’21
What is the most suitable back-end integration for SwiftUI simple data synchronisation with other users?
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
0
0
1.9k
Feb ’21
How to save an audio file using Core Data + CloudKit?
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.
1
0
1.3k
Feb ’21
Initialising CloudKit schema on public database fails for in Core Data with multiple strings (rdar://FB8995024)
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
4
0
3.0k
Feb ’21