Search results for

NSPersistentCloudKitContainer

589 results found

Post

Replies

Boosts

Views

Activity

CoreData & CloudKit toggle iCloud sync (enable/disable)
I want to give the user the option to toggle iCloud sync on and off. So I'm switching between NSPersistentCloudKitContainer and NSPersistenttContainer But... When I switch off the CloudKit synchronization and update the container, the sync is still active. After restarting the app manually the sync is deactivated. This is the same problem some people are describing in the comments here... https://stackoverflow.com/questions/65355720/coredatacloudkit-on-off-icloud-sync-toggle I wasn't able to find a solution. Here is my code: MyApp.swift @main struct MyApp: App { @StateObject private var persistenceContainer = PersistenceController.shared var body: some Scene { WindowGroup { ContentView() .environmentObject(CoreBluetoothViewModel()) .environment(.managedObjectContext, persistenceContainer.container.viewContext) } } } PersistenceController import CoreData class PersistenceController: ObservableObject{ static let shared = PersistenceController() lazy var container: NSPersistentContainer = { setupContain
0
0
1k
Feb ’23
Is History Tracking in Cloudkit shared database needed?
I’ve setup the Cloudkit persistent container with private and shared database (see code below). I’ve enabled NSPersistentHistoryTrackingKey to true also for .shared database. I’ve noticed in the example from Apple that the History Tracking is only enabled in .private but not for .shared. Questions: For a CloudKit setup to sync (a) between owners’ own devices (only private database), and (b) between multiple iCloud Users through .private and .shared databases, Do I need to enable history tracking for .shared database if I want to check the remote changes in the .shared database (or is the history tracking of the .private database of the owner also accessible in the .shared database)? ======================== let APP_BUNDLE_IDENTIFIER = Bundle.main.bundleIdentifier! let APP_GROUP_IDENTIFIER = group. + APP_BUNDLE_IDENTIFIER private func setupPersistentContainer(_ container: NSPersistentCloudKitContainer? = nil, isStartup: Bool = true) -> NSPersistentCloudKitContainer { let container = contai
1
0
730
Jul ’24
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
"This NSPersistentStoreCoordinator has no persistent stores", despite setting up all capabilities
Hi guys, First of all, I'm sorry if this is the wrong place to post this. I'm in the last steps of my task manager app: getting the tasks to sync between devices. However, I get the error This NSPersistentStoreCoordinator has no persistent stores (unknown). It cannot perform a save operation. What does this error exactly mean? My container is initialised so it should have a persistent store, right? I've also enabled all the proper capabilities I'm pretty sure (eg, I've enabled CloudKit, created a container, enabled background fetch and remote notifications.) Here is the code for my data controller: import CoreData import Foundation class DataController: ObservableObject { let container = NSPersistentCloudKitContainer(name: TaskDataModel) init() { guard let description = container.persistentStoreDescriptions.first else { fatalError(Container descriptions not loaded) } description.setOption(true as NSNumber, forKey: NSPersistentHistoryTrackingKey) container.viewContext.mergePolicy = NSMergeByPropertyOb
1
0
2.0k
Aug ’23
How to clean up old NSPersistentStore files after migrating Core Data with CloudKit to App Group container
Hi, I’m trying to migrate Core Data with CloudKit to the shared App Group Container so that widgets can get access to it. So far, I’ve managed to do so with the following code: init() { container = NSPersistentCloudKitContainer(name: “AppName”) let storeDescription = container.persistentStoreDescriptions.first! // Clean up code goes here (explained later) // ... let sharedGroupStoreURL = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: group.com.XXX)!.appendingPathComponent(AppName.sqlite) storeDescription.url = sharedGroupStoreURL container.loadPersistentStores { (storeDescription, error) in if let error = error as NSError? { print(Unresolved error (error), (error.userInfo)) } } container.viewContext.mergePolicy = NSMergeByPropertyObjectTrumpMergePolicy container.viewContext.automaticallyMergesChangesFromParent = true } This tells Core Data to use the shared container. When the new persistentStore loads, it gets seamlessly populated with the data from CloudKit. So far, so good
1
0
691
Jul ’21
Unable to load CloudKit CoreData Store
I have a CoreData model, in a Swift Package with tests. I can successfully run the tests, when I load the model using NSPersistentContainer, however attempting this with NSPersistentCloudKitContainer always fails in the call to loadPersistentStores(completionHandler block: @escaping (NSPersistentStoreDescription, Error?) -> Void) The error is : [CK] BUG IN CLIENT OF CLOUDKIT: Not entitled to listen to push notifications. Please add the 'aps-connection-initiate' entitlement. This issue is described on StackOverflow however, the accepted solution does not appear to work in my case. I have tried adding the aps-connection-initiate key to my App Info.plist, the Test Info.plist and the SPM bundle. No change. (NB. adding this to the entitlements file just breaks auto signing). I have enabled App entitlements for App Groups, Remote Notifications background mode, Push Notifications and iCloud CloudKit with a store identifier. I have checked my model. All relationships have inverses. No unique constraints,
4
0
2.0k
Dec ’22
CloudKit: Handling CKError.partialFailure with pcs_data errors
My iOS app uses Core Data for local data management and NSPersistentCloudKitContainer to sync data with user’s private iCloud storage. The app has been functioning correctly for several years, but recently, some users have started encountering a CKError.partialFailure error when the app attempts to export data to iCloud. Due to the critical nature of export errors, several features in the app have been disabled to prevent potential data duplication. Core Data Setup: lazy var container: NSPersistentContainer = { let container: NSPersistentContainer if storeType == .inMemory { // Used by unit tests container = NSPersistentContainer(name: models) container.persistentStoreDescriptions.first!.url = URL(fileURLWithPath: /dev/null) } else { container = NSPersistentCloudKitContainer(name: models) } container.loadPersistentStores { [weak self] _, error in if let error = error { self?.logger.error(Failed to load persistent store: (error)) fatalError() } } return container }() lazy var context: NSManag
1
0
689
Aug ’24
Cloudkit is broken (sort of) in simulator
I am developing an app that uses NSPersistentCloudKitContainer. I am seeing lots of inconsistency. But....after a long time observing...I strongly believe the simulator implementation of cloudkit is broken. Log in via your icloud Open the built in Apple reminder app in both simulator and on your physical device. You will notice that changes made in simulator propagate reasonably well to the device....but any changes made on device don't propagate to the simulator reminders app...you need to force quit app on simulator for changes to reflect. The ultimate example app is apple notes. It handles sync better than any other app out there. I still am in the process of understanding why my app does not sync as well as notes, eg playing around with things like: container.viewContext.mergePolicy = NSMergeByPropertyStoreTrumpMergePolicy container.viewContext.automaticallyMergesChangesFromParent = true NotificationCenter.default.addObserver(self, selector: #selector(storeRemoteChangeNotification), name: NSNotif
0
0
503
Sep ’20
What is the proper time to deploy CloudKit Schema to Production?
The Statement I have a SwiftUI app that uses CoreData and iCloud with NSPersistentCloudKitContainer prepared for beta testing via TestFlight. The app utilizes iCloud solely as a private database for user data across different devices. The app doesn't use any public or shared database. According to Apple's guidelines, deploying the development schema to production is necessary before submitting to the App Store: Before you publish your app, you must deploy the development schema to the production environment to copy over its record types, fields, and indexes. I am aware that once deployed to production, it's impossible to delete or modify any types or fields: To prevent conflicts, you can’t delete record types or fields that are already in production. Every time you deploy the development schema, its additive changes merge into the production schema. The Questions: When is the appropriate time to deploy the schema to production? Should it be done before beta testing via TestFlight, or is it sufficient
1
0
1.2k
Mar ’24
Initial sync of watchOS app using Core Data and CloudKit
I have an existing iOS/watchOS app that uses a third-party database and WatchConnectivity. For various reasons I am migrating the app to use Core Data with CloudKit. I have everything working using NSPersistentCloudKitContainer. Sync between the iOS and watchOS app are working on my test devices when I start with an empty database. However, I need to import existing user's data when they first install this new version. Some users may have hundreds or thousands of records, but the total database size is under 1-2MB. Data migration/import is working on the iOS side, the Core Data entities are populated on first launch and uploaded to CloudKit (I see in the debug logs that a NSPersistentCloudKitContainer.Event export ends successfully). The problem is launching the watchOS app does not sync the data from CloudKit. I see a import started event but never see it end. I never see any Core Data entities appear on watchOS even after waiting several minutes and re-opening the Watch app multiple times. New enti
3
0
1.1k
Sep ’23
Cannot migrate store in-place: CloudKit integration forbids renaming
Background Core Data driven app, successfully using NSPersistentCloudKitContainer for some time. App is written 100% SwiftUI, currently targeting iOS and macOS targets. Development only, no production release yet. Error... ... Fatal error: Unresolved error Error Domain=NSCocoaErrorDomain Code=134110 An error occurred during persistent store migration. ... reason=Cannot migrate store in-place: CloudKit integration forbids renaming 'foodServes' to 'foodPortions'. Older devices can't process the new relationships. An unusual problem for me... the renaming occurred between version 7 and version 8 of the Core Data model and this is version 13. So if I revert back to version 12, there is no issue. It is only when I add the new Entity in model version 13 that the error occurs. The new entity incudes a relationship back to two other existing entities, but not the Food entity that contains the foodServes -> foodPortions renamingID. To be clear, the error relates to a renamingID that was implemented in the
1
0
2.0k
Feb ’22
Privacy Nutrition Label with encrypted CloudKit attributes
Situation I'm working on an app in which the user can manually enter in data. That data gets locally stored in a CoreData database and from there automatically synced (via NSPersistentCloudKitContainer) to the user private CloudKit database and I selected CloudKit encryption for every attribute. So as the developer I definitely can't access it, but it's stored on some remote server. Ambiguous Documentation The privacy site at https://developer.apple.com/app-store/app-privacy-details/ says stuff like: “Collect” refers to transmitting data off the device in a way that allows you and/or your third-party partners to access it for a period longer than what is necessary to service the transmitted request in real time. If you collect data about your app from Apple frameworks or services [such as MapKit, CloudKit, or App Analytics] you should indicate what data you collect and how you use it. You are not responsible for disclosing data collected by Apple. It's a bit unclear if Apple a third-party in this cas
0
0
935
Jul ’22
CloudKit Why is my Public Database empty?
Hello. I am beta testing an app in TestFlight. I want to use a public database inside the cloudkit container, and I think that I have set things up that way (see below). But my testers can only see their own data and all records are being stored in the Private Database. I'm getting the results I want on my own iPhone (loading the app directly from xCode). But testers are not getting the same experience. It this because I am in TestFlight? Are there settings I have missed? Here is what I have done so far: In my DataController I have this: init(inMemory: Bool = false) { container = NSPersistentCloudKitContainer(name: Main) if inMemory { // this is set in static var preview container.persistentStoreDescriptions.first?.url = URL(fileURLWithPath: /dev/null) } guard let description = container.persistentStoreDescriptions.first else { print(Can't set description) fatalError(Error) } let publicStoreURL = description.url!.deletingLastPathComponent().appendingPathComponent(public.sqlite) let containerIdentifie
2
0
1.4k
Jan ’23
Previews Crash on CoreData model using 'Parent Entity'
I have a CoreData model with two entities, 'User' and 'Player', that both use 'Person' as their 'Parent Entity'. While the App appears to work correctly in the simulator, including with CloudKit via NSPersistentCloudKitContainer, I get a crash in Xcode Previews: libswiftCore.dylib [ AGScoringModel/Persistence.swift:183: Fatal error: #init(inMemory:): Failed to load persistent stores:Error Domain=NSCocoaErrorDomain Code=134110 An error occurred during persistent store migration. UserInfo={sourceURL=file:///Users/ebg/Library/Developer/.../CoreDataStores/private/database.sqlite, reason=Cannot migrate store in-place: Cannot merge multiple root entity source tables into one destination entity root table, destinationURL=file:///Users/ebg/Library/Developer/.../CoreDataStores/private/database.sqlite, NSUnderlyingError=0x600000ce02a0 {Error Domain=NSCocoaErrorDomain Code=134110 An error occurred during persistent store migration. UserInfo={message=Cannot merge multiple root entity source tables into one desti
2
0
1.1k
Jan ’24
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 ’19