Search results for

NSPersistentCloudKitContainer

589 results found

Post

Replies

Boosts

Views

Activity

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
Aug ’22
Error when calling initializeCloudKitSchema
I am trying to setup my CloudKit schema from CoreData using the NSPersistentCloudKitContainer but getting an error when calling try container.initializeCloudKitSchema() The error: Error Domain=NSCocoaErrorDomain Code=134060 A Core Data error occurred. UserInfo={encounteredErrors=( Error Domain=NSCocoaErrorDomain Code=134406 Request '07443E71-32AC-4E63-A163-AAF940FE1AD6' was aborted because the mirroring delegate never successfully initialized due to error: UserInfo={NSLocalizedFailureReason=Request '07443E71-32AC-4E63-A163-AAF940FE1AD6' was aborted because the mirroring delegate never successfully initialized due to error: } )} My container is iCloud., and is reflected in the Entitlement file.
1
0
1.1k
Aug ’22
Reply to Not receiving Persistent Store Remote Change Notification.
I think in built constants have to be used for keys so i changed the code to following... - (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) { #ifdef DEBUG NSLog(@Unresolved error %@, %@, error, error.userInfo); #endif abort(); } else { #ifdef DEBUG NSLog(@Store successfully initialized); #endif [storeDescription setOption:[NSNumber numberWithBool:YES] forKey:NSPersistentHistoryTrackingKey]; [storeDescription setOption:[NSNumber numberWithBool:YES] forKey:NSPersistentStoreRemoteChangeNotificationPostOptionKey]; } }]; } return _persistentContainer
Aug ’22
App getting killed by iOS while NSPersistentCloudKitContainer syncs
I have been spending the last several weeks implementing NSPersistentCloudKitContainer in my app, and it is most of the way there. Unfortunately, I keep running into an issue where after several days of successful syncing between devices, each device begins to crash after about a minute of use, repeatedly. The crash report points to a SQL thread doing things with the CoreData and CloudKit frameworks — none of my code whatsoever. It is the typical “CPU: 48 seconds cpu time over 58 seconds (82% cpu average), exceeding limit of 80% cpu over 60 seconds” issue. If I run the devices hooked up to Xcode and debug, I see the thread spin up and the log shows it chugging through changed CKRecords it needs to import, just like normal. If I leave the devices hooked up to Xcode, they eventually make it through this huge job and the devices become usable again. Once one device is in this state, the problem also occurs on new devices trying to download from the cloud for the first time. I’ve attached a screenshot of
9
0
2.7k
Aug ’22
Reply to Not receiving Persistent Store Remote Change Notification.
By mistake i set the store descriptions inside if (error ! = nil) I changed that... yet no go... - (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) { #ifdef DEBUG NSLog(@Unresolved error %@, %@, error, error.userInfo); #endif abort(); } else #ifdef DEBUG NSLog(@Store successfully initialized); #endif [storeDescription setOption:[NSNumber numberWithBool:YES] forKey:@PersistentHistoryTracking]; [storeDescription setOption:[NSNumber numberWithBool:YES] forKey:@NSPersistentStoreRemoteChangeNotificationOptionKey]; }]; } } return _persistentContainer;
Aug ’22
Reply to Error: Failed to sync user keys in simulator
Problem 1: NSPersistentCloudKitContainer doesn't seem to work on simulator Solution: Use device, haven't found a way to make it work on the simulator. Problem2 When using CloudKit APIs (not NSPersistentCloudKitContainer) on the simulator I was getting CKError.notAuthenticated even though I had signed into iCloud on the simulator Root cause This happens when 2FA was enabled on the iCloud account but the 2FA code was asked on the simulator Solution Go to https://appleid.apple.com/, select devices on the sidebar Remove simulator (I found 2 simulators, removed both) Reset Xcode simulator Log into iCloud on the simulator Run the app Hopefully that should work.
Aug ’22
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
Aug ’22
Reply to CoreData+CloudKit custom Zone
Are you using manually syncing your CloudKit with CoreData or are you using NSPersistentCloudKitContainer? If you using NSPersistentCloudKitContainer does the syncing for you, don't have to set any custom zone, it would set a custom zone automatically. If you are doing it manually, then you would need to set a custom zone when you are saving a record and when you are retrieving it not while loading the container's persistent stores (which is what you are doing).
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Aug ’22
Are CKRecords Guaranteed to be Added to an NSPersistentCloudKitContainer Store in creationDate order?
I am trying to deduplicate data created by NSPersistentCloudKitContainer in my app. I have a universal app, with Share Extensions on both macOS and iOS. On each platform I share a store between the app and the extension with an App Group. The app and the extensions are both configured to sync to CloudKit. (This means local sharing is handled when offline, and a remote share extension will sync to CloudKit work when the main app is closed) This configuration is causing duplicates to be generated. I believe this is because when the macOS app is open, both it and the macOS share extension will try and (almost simultaneously) sync a newly shared object, resulting in two copies in CloudKit. On the macOS app, I can look through the persistent history and see the insertion 'author'. The first insertion is made by the extension macOSShareExtension, the second is made by NSCloudKitMirroringDelegate.import. I could easily make a choice to delete the second object. However, at the same time, on the iOS app, I w
2
0
962
Aug ’22
NSPersistentCloudKitContainer: Exclude Relationship From Share
I am trying to add CloudKit sharing to my app using the new iOS 15 share method https://developer.apple.com/documentation/coredata/nspersistentcloudkitcontainer/3746834-sharemanagedobjects In the app there are 3 core data entities (Folder, Item, Comment) with the following relationships: A Folder contains many Items An Item has many Comments I want to use CloudKit to share just the Item entity, not any of its relationships. Is this possible to do with the share(_:to:completion:) method? Currently, when I pass an Item to the share method it also includes the Folder and Comments in the CKShare. How do I prevent this? A similar question was posted here with no response: https://developer.apple.com/forums/thread/697630
1
0
901
Jun ’22
NSPersistentCloudKitContainer - notification
I would like to implement notifications about NSPersistentCloudKitContainer I find this classe but I receive no notifications in my app!?! Do I need more settings to use it? thanx for your help import Combine import CoreData @available(iOS 14.0, *) class SyncMonitor { /// Where we store Combine cancellables for publishers we're listening to, e.g. NSPersistentCloudKitContainer's notifications. fileprivate var disposables = Set() init() { NotificationCenter.default.publisher(for: NSPersistentCloudKitContainer.eventChangedNotification) .sink(receiveValue: { notification in if let cloudEvent = notification.userInfo?[NSPersistentCloudKitContainer.eventNotificationUserInfoKey] as? NSPersistentCloudKitContainer.Event { // NSPersistentCloudKitContainer sends a notification when an event starts, and another when it // ends. If it has an endDate, it means the event finished. if cloudEvent.endDate == nil { print(Starting an event...) // You could check the type, but I'm trying to keep this bri
1
0
1.9k
Jun ’22
Reply to Good tutorial for hooking CloudKit into a SwiftUI project.
If anyone is curious the first part of a post (https://www.andrewcbancroft.com/blog/ios-development/data-persistence/getting-started-with-nspersistentcloudkitcontainer/) got me started and then the Apple Documentation - specifically Setting Up Core Data with CloudKit to me the rest of the way. I mostly jumped around the documentation from there (got data loading when I started the app) and then Hacking with Swift got me the rest of the way.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jun ’22
What are some reliable mechanism to prevent data duplication in CoreData CloudKit?
Every of our data row, contains an unique uuid column. Previously, before adopting CloudKit, the uuid column has a unique constraint. This enables us to prevent data duplication. Now, we start to integrate CloudKit, into our existing CoreData. Such unique constraint is removed. The following user flow, will cause data duplication. Steps to cause data duplication when using CloudKit Launch the app for the first time. Since there is empty data, a pre-defined data with pre-defined uuid is generated. The pre-defined data is sync to iCloud. The app is uninstalled. The app is re-installed. Launch the app for the first time. Since there is empty data, a pre-defined data with pre-defined uuid is generated. Previous old pre-defined data from step 3, is sync to the device. We are now having 2 pre-defined data with same uuid! :( I was wondering, is there a way for us to prevent such duplication? In step 8, we wish we have a way to execute such logic before written into CoreData Check whether such uuid exists in CoreData
1
0
1.3k
Jun ’22
Core Data Entity Inside Another Entity
So I have an entity in my core data model called recipe. I need to create another entity containing a recipe and a date that the recipe is assigned to. Can I do this similar to the way I've done it in the image and just save a Recipe object in the initialization of PlannedRecipe object in the Persistence file? Basically I just need to know how to add a entity in an entity using this core data model and persistence file. Persistence file: import CoreData struct PersistenceController { static let shared = PersistenceController() let container: NSPersistentCloudKitContainer init(inMemory: Bool = false) { container = NSPersistentCloudKitContainer(name: ReciPrep) 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)) } }) container.viewContext.automaticallyMergesChangesFromParent = tru
2
0
1.2k
Jun ’22
Reply to WidgetKit and CoreData/CloudKit
In testing today, syncing in the background with NSPersistentCloudKitContainer seems to be working more reliably with the iOS 16 SDK. The first time you change something on another device it still seems to schedule a task to perform that work with utility priority (via -[NSCloudKitMirroringDelegate checkAndScheduleImportIfNecessary:andStartAfterDate:] which logs Scheduling automated import with activity CKSchedulerActivity priority 2 Utility), so it doesn't execute right away. If you change it again then I'm seeing it does immediately import the two accumulated changes (NSCloudKitMirroringDelegate Beginning automated import - ImportActivity - in response to activity, then -[PFCloudKitImportRecordsWorkItem applyAccumulatedChangesToStore:inManagedObjectContext:withStoreMonitor:madeChanges:error:] followed by NSCloudKitMirroringImportRequest Importing updated records) which triggers NSManagedObjectContextObjectsDidChange, NSPersistentStoreRemoteChange, and NSPersistentCloudKitContainer.eventChangedNotif
Jun ’22