Search results for

NSPersistentCloudKitContainer

589 results found

Post

Replies

Boosts

Views

Activity

Core Data + CloudKit crash on startup only in production
Hi, My macOS app's production build is crashing on start with an unhelpful crashdump. In the console, the only error in the Console is BUG IN CLIENT OF CLOUDKIT: Not entitled to listen to push notifications. Please add the 'com.apple.private.aps-connection-initiate' entitlement. Adding this entitlement to my entitlements.plist breaks the app entirely (Unsatisfied entitlements). Here is how I'm loading my persisten store: lazy var persistentContainer: NSPersistentCloudKitContainer = { let container = NSPersistentCloudKitContainer(name: ChatModel) guard let description = container.persistentStoreDescriptions.first else { fatalError(###(#function): Failed to retrieve a persistent store description.) } if(UserDefaults.standard.bool(forKey: StoredPreferenceKey.iCloudSync)){ description.cloudKitContainerOptions = NSPersistentCloudKitContainerOptions(containerIdentifier: iCloud.XXXXX) } else { description.cloudKitContainerOptions = nil } description.setOption(true as NSNumber, forKey: NSPersistentH
2
0
955
May ’23
CloudKit initial sync and background audio leads to high CPU app termination
I have a music app that can play in the background, using AVQueuePlayer. I'm in the process of adding support for CloudKit sync of the CoreData store, switching from NSPersistentContainer to NSPersistentCloudKitContainer. The initial sync can be fairly large (10,000+ records), depending on how much the user has used the app. The issue I'm seeing is this: ✅ When the app is in the foreground, CloudKit sync uses a lot of CPU, nearly 100% for a long time (this is expected during the initial sync). ✅ If I AM NOT playing music, when I put the app in the background, CloudKit sync eventually stops syncing until I bring the app to the foreground again (this is also expected). ❌ If I AM playing music, when I put the app in the background, CloudKit never stops syncing, which leads the system to terminate the app after a certain amount of time due to high CPU usage. Is there any way to pause the CloudKit sync when the app is in the background or is there any way to mitigate this?
3
0
2.6k
Jun ’23
Field '___modTime' is not marked sortable
I'm using NSPersistentCloudKitContainer and I'm getting warnings in the console saying: CoreData: CloudKit: CoreData+CloudKit: -[NSCloudKitMirroringDelegate _scheduleAutomatedExportWithLabel:activity:completionHandler:]_block_invoke(3457): - Finished automatic export - AppActivationExport - with result: storeIdentifier: F2C60E7A-CEC4-44F2-B467-7324C065AD33 success: 0 madeChanges: 0 error: Error Domain=NSCocoaErrorDomain Code=134406 Request '1FA53D40-43FB-4751-8719-0D26393D5301' was aborted because the mirroring delegate never successfully initialized due to error: UserInfo={NSLocalizedFailureReason=Request '1FA53D40-43FB-4751-8719-0D26393D5301' was aborted because the mirroring delegate never successfully initialized due to error: } I have added indexes for recordName and modifiedTimestamp to all my records as queryable as per the instructions.
2
0
1k
May ’23
CloudKit - initializeCloudKitSchema error
Hi, I've previously used a local core data database successfully with my app and now I wanted to use NSPersistentCloudKitContainer to store the data in CloudKit. However when I do container.initializeCloudKitSchema(options: []) I receive an error which I'm not able to comprehend: CoreData: error: CoreData+CloudKit: -[NSCloudKitMirroringDelegate _requestAbortedNotInitialized:](2112): - Never successfully initialized and cannot execute request ' 17E8940B-00D6-4D01-AA78-6A04EBEBC957' due to error: ... 9 Batch Request Failed CKError's omited ... }> I also get this error in the console: Atomic failure = I've tried to reset Reset Environment in the CloudKit dashboard to no avail.
1
0
1.1k
Apr ’23
Reply to preload core data from cloud kit
This what I use in my apps (during the initialisation of my Data Controller): self.mainContainer = { let container = NSPersistentCloudKitContainer(name: MyDataModel) container.loadPersistentStores(completionHandler: { description, error in if let error = error { print(**** ERROR loading persistent store (error)) } //Setup auto merge of Cloudkit data container.viewContext.automaticallyMergesChangesFromParent = true container.viewContext.mergePolicy = NSMergeByPropertyObjectTrumpMergePolicy //Set the Query generation to .current. for dynamically updating views from Cloudkit try? container.viewContext.setQueryGenerationFrom(.current) }) return container }() The key lines are the 2 below //Setup auto merge. Also, be sure to have enabled Remote Notifications in Background modes of the App's Signing and Capabilities. I hope this helps. Regards, Michaela
Apr ’23
Reply to Core Data Plus CloudKit - Potential Issue / Question about Binary Data w/ External Storage
hi, as long as you're OK with I will never manipulate the CloudKit data directly, then i don't see what the problem is. i doubt that the NSPersistentCloudKitContainer designers ever intended for users to be interacting directly in code with CKRecords and making an end run around what NSPersistentCloudKitContainer does for you automatically. however, that aside, i do recall reading at one point that Core Data does not necessarily use external storage just because you checked Allows External Storage. it could be the case that Core Data made such decisions about your data at some point; if so, the CloudKit representation of what NSPersistentCloudKitContainer does for you would probably respect that decision. hope that helps, DMG
Apr ’23
Reply to CloudKit container error
In case others get stuck with this, I created a new container and ensured the container = NSPersistentCloudKitContainer(name: name) , and the CoreData file was the same name and all went fine afer. I also made sure the container name, et.al. was a short name and was different from the BundleID. Blessings, --Mark
Apr ’23
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
Reply to In-app storage/sync strategy for shared objects
How important is user privacy? How important is security? How are you planning to pay for cloud services like FireBase or AppWrite? I choose CloudKit (and CoreData), time and again, because, user data is private and secure by default, the capability to share between users is built in on top of that privacy and security, and users pay for their own cloud storage, not me. In 2019, Apple introduced a sync system between the CloudKit and CoreData, called NSPersistentCloudKitContainer, which might server you well. If you want more control, check out CloudCore. And for Android, check out cloudkit_flutter. fwiw
Topic: Programming Languages SubTopic: Swift Tags:
Jan ’23
CoreData: Operation could not be completed 'Foundation_GenericObjError error 0'
I'm encountering the error 'Operation could not be completed 'Foundation_GenericObjError error 0'' when loading my canvas on my SignupView. No errors are showing in my code, I've tried all sorts of fixes and nothing seems to work. Any help would be appreciated, if you need more code I will update post. SignupView @Environment(.managedObjectContext) private var viewContext @FetchRequest( sortDescriptors: [NSSortDescriptor(keyPath: Account.userSince, ascending: true)], animation: .default) private var savedAccounts: FetchedResults .onAppear(perform: userData) .fullScreenCover(isPresented:$showHomeView, content: { HomeView().environment(.managedObjectContext, viewContext) func userData() { Auth.auth().addStateDidChangeListener { auth, user in if let currentUser = user { if savedAccounts.count == 0 { // Add data to Core Data let userDataToSave = Account(context: viewContext) userDataToSave.name = currentUser.displayName userDataToSave.userID = currentUser.uid userDataToSave.numberOfCertificates = 0 userDataToSave
1
0
1.7k
Jan ’23
Timeout during initialization of CloudKit schema
Hi everybody, I am having trouble further initializing my CloudKit schema with an NSPersistentCloudKitContainer and store descriptions for booth public and private database scopes. The execution environment is macOS 12.3.1. container.newBackgroundContext().perform { do { print(Starting to initialize CloudKit Schema...) try container.initializeCloudKitSchema(options: []) print(CloudKit Schema succesfully initialized.) } catch { print(error) } } After about 30 seconds, the above code block goes into the catch statement with the following error: Error Domain=NSCocoaErrorDomain Code=134060 A Core Data error occurred. UserInfo={NSLocalizedFailureReason=Failed to initialize CloudKit schema because the requests timed out (a 30s wait failed).} During that 30 seconds of my app trying to init the schema, I noticed that the CloudKit Console was also having trouble communicating correctly with the container: When I reload the CloudKit Console after the init got into the 30s timeout. The Console has no more troub
2
0
1.4k
Jan ’23
Force a NSPersistentCloudKitContainer sync
I have a SwiftUI app sitting on top of a CoreData + CloudKit stack. If I have the app running on multiple devices, a change on one device will not always be reflected on the others. However, restarting the app on the other device will pick up the change. For example:Device A and Device B both have the app running. Device B has it in the background.Device A changes Record 1. Device B returns to the foreground, but does not see the change to Record 1Kill the app on Device B, relaunch, and it sees the changeIt seems that the cloudkit process isn't always getting change notifications from iCloud (note that this happens on actual devices, not just the sim). If we could tell the container Hey, I just retuned to the foreground, maybe check to see if anything has changed?, that would, I think, fix the problem. I can't tear down my CoreData stack without rebuilding the entire app (since the main thread context is pushed down into SwiftUI).Is there a way to force this update?Thanks!Ben
4
0
4.7k
Dec ’22
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
Dec ’22
NSPersistentCloudKitContainer - Import failed because applying the accumulated changes hit an unhandled exception
When I use NSPersistentCloudKitContainer to sync data, I receive error Code=134421/134406 Import failed because applying the accumulated changes hit an unhandled exception. iOS/iPadOS 15 beta 5 - iOS/iPadOS 15 beta 7(latest) When this error appears, data can not be import/merged from iCloud. Delete app and reinstall is not working. Same momd on macOS 12(Catalyst, with full data upgrated from macOS 11) works fine. Maybe a system bug? Merge Policy: context.mergePolicy = NSMergeByPropertyObjectTrumpMergePolicy context.automaticallyMergesChangesFromParent = true Console log here: CoreData: error: CoreData+CloudKit: -[NSCloudKitMirroringDelegate _requestAbortedNotInitialized:](1826): - Never successfully initialized and cannot execute request ' B7974D4D-C5DA-413E-AE3B-072C88D38D47' due to error: Error Domain=NSCocoaErrorDomain Code=134421 Import failed because applying the accumulated changes hit an unhandled exception. UserInfo={NSLocalizedFailureReason=Import failed because applying the accumulated cha
15
0
7.2k
Dec ’22