Search results for

NSPersistentCloudKitContainer

589 results found

Post

Replies

Boosts

Views

Activity

How to read/write to App1’s database from App2?
I have 2 apps in the App Store, and each uses the private database in its own CloudKit container. (ie, App1 uses “iCloud.com.company.App1” and App2 uses “iCloud.com.company.App2”) I want to add a feature to App2 which will require App2 to read/write to the App1 database. To be clear, we’re talking about 2 apps, 2 private databases, but all access occurs under the same user’s AppleID. In App2, I’ve tried to create 2 NSPersistentCloudKitContainers - one for each App’s database as follows: @main struct App2: App { @StateObject var app1DB = PersistenceApp1.shared @StateObject var app2DB = PersistenceApp2.shared @SceneBuilder var body: some Scene { WindowGroup { NavigationView { ContentView() .environmentObject(app1DB) .environmentObject(app2DB) } } } } …where each Persistence object is defined like this… class PersistenceApp1: ObservableObject { static let shared = PersistenceApp1() let container: NSPersistentCloudKitContainer init(inMemory: Bool = false) { container = NSPersistentCloudKitContainer
2
0
1.3k
Sep ’22
Can a private database entity have a relationship to a public database entity?
I’m using NSPersistentCloudKitContainer and I’m utilising the public database and also the user’s private database. For example I have an entity called Category which has a many-to-many relationship to an entity called NewsArticle. So the NewsArticles exist in the public database for the user to browse, but he can add them to a category which will live in his private database. So that’s my question, is it possible for an entity which exists a in the private database to have a relationship to another entity in a public database?
1
0
959
May ’23
CoreData+CloudKit integration issue
Hello. I'm trying to setup CoreData+CloudKit integration. But I receive following errors right after NSPersistentCloudKitContainer configuration. CoreData: error: CoreData+CloudKit: -[NSCloudKitMirroringDelegate _performSetupRequest:]_block_invoke(939): : Failed to set up CloudKit integration for store: (URL: file:///var/mobile/Containers/Data/Application/18992BCF-7F0C-4271-B106-947B8F52A723/Library/Application%20Support/App.sqlite) Error Domain=NSCocoaErrorDomain Code=134060 A Core Data error occurred. UserInfo={NSLocalizedFailureReason=The mirroring delegate could not initialize because it's store was removed from the coordinator.} Here is the code of persistent container setup: self.persistentContainer = NSPersistentCloudKitContainer(name: containerName) let localStorage = NSPersistentStoreDescription(url: storageURL) let localStorageOptions = NSPersistentCloudKitContainerOptions(containerIdentifier: iCloud.com.myapp) localStorageOptions.databaseScope = .private localStorage.cloudKitCont
0
0
1.1k
Aug ’21
Is it possible to unload/change the PersistenceStore in a SwiftUI App during runtime
Hi, I want to activate/deactivate the CloudKit Sync during App runtime in a user settings view. Basically this works fine. Every time I toggle between the NSPersistentContainer and the NSPersistentCloudKitContainer, I increase the persistence.persistenceContainerReloaded attribute and the whole view hierarchy will be reloaded. Thus all changes are passed through the whole app. During the reload phase I have to load a new persistence store by container.loadPersistentStores(...). Unfortunately, I cannot remove the old persistence store before loading the new one. The app crashes immediately, because the store and viewContext is still in use. Therefore, I just create a new one and trigger the reload. Afterwards every view is using the new viewContext. But somewhere in the background there is still the old persistence store with CloudKit Sync active and pushes every local change to the cloud. Changes on the cloud from other devices are not received anymore. Does someone has any idea, how to correctly unl
6
0
1.3k
Dec ’21
Health data like daily grams of protein in Core Data CloudKit container?
Hi, I wrote an app that helps me count how many grams of protein I eat each day. I'm the only user now, and the app uses Core Data and the CloudKit container, to sync data across my devices. I was thinking about releasing it in App Store, and I noticed this in the app review guidelines: may not store personal health information in iCloud. Does that mean we cannot use Core Data with NSPersistentCloudKitContainer for an app like this? Thanks.
0
0
395
Jul ’20
Persisting a PKDrawing to iCloud
I have an App in which I am using NSPersistentCloudKitContainer to store user's drawings, and to have them in sync across multiple devices. To store the drawings, I am using a Binary Data attribute in my Core Data entity. In this attribute I am saving the data representation of the drawing by using this API https://developer.apple.com/documentation/pencilkit/pkdrawing/3281878-datarepresentation I have observed that for some drawings this data representation consumes a huge amount of data, and that generates synchronisation problems among devices. Is there a better approach to persist PKDrawings without this problem?
2
0
1.2k
Jun ’20
Fetch data from CloudKit to app when app is in background
Hello I have an app that uses Core Data with CloudKit to store data. When I am in the app (using the app) and create some new data on an other device, the data is fetched in a few seconds and I see it immediately, however if I am not using the app and create some new data on an other device, I have to enter the app and then the data starts fetching, is there a way to fetch data even if I am not using the app. Here is my core data stack: import CoreData import Combine class PersistenceController { static let shared = PersistenceController() let container: NSPersistentCloudKitContainer init() { container = NSPersistentCloudKitContainer(name: CoreData) guard let fileContainer = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: APP_GROUP_NAME)?.appendingPathComponent(CoreData.sqlite) else { fatalError(Shared file container could not be created.) } let storeDescription = NSPersistentStoreDescription(url: fileContainer) storeDescription.setOption(true as NSNumber, forKey: NSP
1
0
1.8k
Dec ’21
Widget error upon restore iPhone: The file "Name.sqlite" couldn't be opened
I have an app that uses NSPersistentCloudKitContainer stored in a shared location via App Groups so my widget can fetch data to display. It works. But if you reset your iPhone and restore it from a backup, an error occurs: The file Name.sqlite couldn't be opened. I suspect this happens because the widget is created before the app's data is restored. Restarting the iPhone is the only way to fix it though, opening the app and reloading timelines does not. Anything I can do to fix that to not require turning it off and on again?
12
0
256
Jun ’25
Reply to Best Practices for Binary Data (“Allows External Storage”) in Core Data with CloudKit Sync
Thanks so much, @tbartelmess1—this is super helpful, and really appreciated a bit more context from our app: App context (what we store) The blobs we persist will be user-generated cruise photos, we would downsize those to more manageable size as iphone format photos can be quite big, but they would still be in the 1-3 mb after downsizing Realistic volume per active user: a few hundred images/year; heavy users could reach low thousands over time. Decision: use Core Data Binary Data + “Allows External Storage” We’ll keep originals as Binary Data (Allows External Storage) so Core Data handles externalization transparently, my philosophy has always been to offload as much work to the system services as possible. We’ll keep thumbnails as well inline in coredata (let coredata decide but likely will be inline (blob)). CloudKit mirroring We’ll rely on NSPersistentCloudKitContainer mirroring; we understand CloudKit decides when an attribute becomes a CKAsset independently of Core Data’s externalization thres
Oct ’25
Core Data + Cloudkit not synching
I have a Core Data + Couldkit App where any changes made on other device is not synched. I had to call the fetch method again refresh the data. I even added the necessary lines, let container = NSPersistentCloudKitContainer(name: myappcontainername) container.viewContext.automaticallyMergesChangesFromParent = true The following are the CoreData logs after making a change, CoreData+CloudKit: -[NSCloudKitMirroringDelegate finishedAutomatedRequestWithResult:](2119): Finished request '<NSCloudKitMirroringExportRequest: 0x6> -UUID' with result: <NSCloudKitMirroringResult: 0x> success: 1 madeChanges: 1 error: (null) What else should I be doing to make this work?
1
0
679
Jul ’20
How to import data from iPhone system File to the app other than the app's iCloud at first through Share Extension?
The local data in iPhone system File is inserted to the app core data through Share Extension. The app uses NSPersistentCloudKitContainer to sync core data. But when importing local data from iPhone local File, the data always go to iCloud of the app at first and then syncing data to the app from iCloud. This leads to that the app cannot import data when the iCloud drive is closed or the iCloud is full. Is there any way to import data to the app other than to the app's iCloud at first?
0
0
871
Aug ’20
Migrating iOS 13 app to 14: how to manage AppDelegate context code for CoreData?
I'm in the middle of updating my app to only support iOS 14+ and am moving to the new @main app structure. I'm trying to figure out how to deal with code in my App and Scene Delegate: mainly code related to Core Data and CloudKit persistent container. Stuff like lazy var persistentContainer: NSPersistentCloudKitContainer = {...} and let context = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext context.mergePolicy = NSMergeByPropertyObjectTrumpMergePolicy context.automaticallyMergesChangesFromParent = true Where do I put this kind of stuff in the new @main world?
1
0
1.1k
Jul ’20
Old local persistent store to new CloudKit store- lightweight migration
I have a new model which syncs to cloudkit. I'have to migrate my old core data store which is local to the new model which will store in cloudkit. I'm not sure how to perform this migration. The container is initialised correctly and the Mapping Model is mapping my entities and attributes correctly. There are no errors. Yet, I do not see my old records upon fetching. I found this lines of code here... NSDictionary *optionsDictionary = [[NSDictionary alloc] initWithObjectsAndKeys: [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, [NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption, <#Ubiquitous content name#>, NSPersistentStoreUbiquitousContentNameKey, nil]; However, I'm not sure where to add it. Since, I had created a new project folder with core data + CloudKit (and imported the old model), this is the method i got in AppDelegate which initialises the store... - (NSPersistentCloudKitContainer *)persistentContainer { // The persistent container for t
5
0
754
Dec ’21
Not receiving Persistent Store Remote Change Notification.
Before the code... CloudKit, background mode (remote notifications) and push notifications are added to Capabilities. Background sync is working fine and view loads current store on manual fetch. Code that initialises the persistent container in app delegate... - (NSPersistentCloudKitContainer *)persistentContainer { // The persistent container for the application. This implementation creates and returns a container, having loaded the store for the application to it. @synchronized (self) { if (_persistentContainer == nil) { _persistentContainer = [[NSPersistentCloudKitContainer alloc] initWithName:@Expenses]; [_persistentContainer loadPersistentStoresWithCompletionHandler:^(NSPersistentStoreDescription *storeDescription, NSError *error) { if (error != nil) { __block NSPersistentStoreDescription *sDescription = storeDescription; dispatch_async(dispatch_get_main_queue(), ^(){ [sDescription setOption:[NSNumber numberWithBool:YES] forKey:@PersistentHistoryTracking]; [sDescription setOption:[NSNu
4
0
1.8k
Aug ’22
Possible to override background push limits during development?
The video discusses limits to background pushes. I'm unable to finish developing my app that uses NSPersistentCloudKitContainer on iOS 14 because I believe background push notifications are being limited by the system so I am unable to test how the app behaves when it is suspended and a background push arrives. In fact I cannot get any background pushes to arrive at all, however pushes do arrive when the app is running in the foreground. Is there perhaps a development entitlement or launch param to override all limits so I can finish my app? And if not, can this feature be added please?
0
0
1.1k
Sep ’20