Search results for

NSPersistentCloudKitContainer

589 results found

Post

Replies

Boosts

Views

Activity

Share sheet configuration
I'm trying to configure the share sheet. My project uses techniques from the Apple Sample project called CoreDataCloudKitShare which is found here: https://developer.apple.com/documentation/coredata/sharing_core_data_objects_between_icloud_users# In this sample code there's a PersistenceController which is an NSPersistentCloudKitContainer. In the PersistenceController+SharingUtilities file there are some extensions, and one of them is this: func configure(share: CKShare, with photo: Photo? = nil) { share[CKShare.SystemFieldKey.title] = A cool photo } This text A cool photo seems to be the only bespoke configuration of the share sheet within this project. I want to have more options to control the share sheet, does anyone know how this might be achieved? Thank you!
Topic: UI Frameworks SubTopic: SwiftUI
1
0
679
Nov ’24
SwiftData + CKSyncEngine
Hi, I'm building a habit tracking app for iOS and macOS. I want to use up to date technologies, so I'm using SwiftUI and SwiftData. I want to store user data locally on device and also sync data between device and iCloud server so that the user could use the app conveniently on multiple devices (iPhone, iPad, Mac). I already tried SwiftData + NSPersistentCloudKitContainer, but I need to control when to sync data, which I can't control with NSPersistentCloudKitContainer. For example, I want to upload data to server right after data is saved locally and download data from server on every app open, on pull-to-refresh etc. I also need to monitor sync progress, so I can update the UI and run code based on the progress. For example, when downloading data from server to device is in progress, show Loading... UI, and when downloading finishes, I want to run some app business logic code and update UI. So I'm considering switching from NSPersistentCloudKitContainer to CKSyncEngine, because it
3
0
1.4k
Dec ’24
NSPersistentCloudKitContainer Import failed (incomprehensible archive)
I am using NSPersistentCloudKitContainer and I decided to add a property to an entity. I accidentally ran try! container.initializeCloudKitSchema(options: []) while using the production container in Xcode (com.apple.developer.icloud-container-environment) which throw a couple of errors and created some FAKE_ records in my production container. So I changed to my development container and ran the try! container.initializeCloudKitSchema(options: []) and now it succeeded. After that I cleaned up the FAKE_ records scattered in production container but in Xcode when I'm running I now get these logs in the console (and I can't seem to get rid of them): error: CoreData+CloudKit: -[NSCloudKitMirroringDelegate _importFinishedWithResult:importer:](1398): : Import failed with error: Error Domain=NSCocoaErrorDomain Code=4864 *** -[NSKeyedUnarchiver _initForReadingFromData:error:throwLegacyExceptions:]: incomprehensible archive (0x53, 0x6f, 0x6d, 0x65, 0x20, 0x73, 0x61, 0x6d) UserInfo={NSDebugDescription=*** -[NS
3
0
541
Dec ’24
Reply to NSPersistentCloudKitContainer Import failed (incomprehensible archive)
Our general set of debugging / inspection Tech Notes are: https://developer.apple.com/documentation/technotes/tn3163-understanding-the-synchronization-of-nspersistentcloudkitcontainer https://developer.apple.com/documentation/technotes/tn3162-understanding-cloudkit-throttles https://developer.apple.com/documentation/technotes/tn3164-debugging-the-synchronization-of-nspersistentcloudkitcontainer If you set an exception breakpoint in Xcode you can probably capture call stack where the keyed archiver exception is thrown. That, the store files from the device having issues, and a sysdiagnose would make a good feedback report for further investigation. We include instructions for capture a sysdiagnose in TN3163.
Dec ’24
Disable SwiftData CloudKit sync when iCloud account is unavailable
I have a widely-used app that lets users keep track of personal data. This data is persisted with SwiftData, and synced with CloudKit. I understand that if the user's iCloud account changes on a device (for example, user logs out or toggles off an app's access to iCloud), then NSPersistentCloudKitContainer will erase the local data records on app launch. This is intentional behavior, intended as a privacy feature. However, we are receiving regular reports from users for whom the system has incorrectly indicated that the app's access to iCloud is unavailable, even when the user hasn't logged out or toggled off permission to access iCloud. This triggers the behavior to clear the local records, and even though the data is still available in iCloud, to the user, it looks like their data has disappeared for no reason. Helping the user find and troubleshoot their iCloud app data settings can be very difficult, since in many cases the user has no idea what iCloud is, and we can't link them directly to the c
1
0
1.1k
Jan ’25
Reply to Disable SwiftData CloudKit sync when iCloud account is unavailable
To work around this and improve the user experience, we want to use CKContainer.accountStatus to check if the user has an available iCloud account, and if not, disable the CloudKit sync before it erases the local data. This is fine but doesn't completely solve your problem: While your app is running, a user can launch Settings.app and log out their iCloud account or turn off iCloud for your app, which still triggers an account change, but your app can't respond because it only checks the account availability at the beginning of a launch session. You can probably observe the CKAccountChanged notification, but then there may have a race – NSPersistentCloudKitContainer may still erase the data before you release the current model container. However, we are receiving regular reports from users for whom the system has incorrectly indicated that the app's access to iCloud is unavailable, even when the user hasn't logged out or toggled off permission to access iCloud. This triggers the behavior to clear the
Jan ’25
Reply to SwiftData data duplication
SwiftData + CloudKit is currently based on NSPersistentCloudKitContainer. Duplicate data can be generated if you have multiple app instances uploading a same piece of data, as discussed in Remove duplicate data. NSPersistentCloudKitContainer doesn't support unique constraints as of today, and so you will need to remove duplicate data with your own algorithm and code. Best, —— Ziqiao Chen  Worldwide Developer Relations.
Jan ’25
Reply to Database not deploying to CloudKit
Did you ever run your app and save some data to the CloudKit-backed Core Data store? NSPersistentCloudKitContainer only creates the custom zone when there is data. Also, you need to initialize the CloudKit schema, if not yet. See Create the CloudKit schema for the more details. Best, —— Ziqiao Chen  Worldwide Developer Relations.
Jan ’25
Reply to MAJOR Core Data Issues with iOS 18 and sdk - Data Missing for many users?!
Hi, Thanks for your response. I don't think we do any of the things you are concerned about. Here is some of the code I use to set up the CoreData/Cloudkit stack and have been using this for a few years now. Nothing changed here in at least 12 months (I am not exactly a piker in this realm :) : class CoreDataUtil: NSObject { @objc var pc = NSPersistentCloudKitContainer(name:iphemeris) private lazy var historyRequestQueue = DispatchQueue(label:history) let coreDataLogSubsystem = com.iPhemeris.coreData let coreDataLogger = Logger(subsystem:com.iPhemeris.coreData, category:Cloudkit) @objc var useiCloud:Bool = userSettings.bool(forKey:UseIcloudKey) { didSet { userSettings.set(useiCloud, forKey:UseIcloudKey) if(pc.persistentStoreCoordinator.persistentStores.count > 0) { let store = pc.persistentStoreCoordinator.persistentStores[0] do { try pc.persistentStoreCoordinator.remove(store) } catch { coreDataLogger.log(*** CoreDataUtil toggle use iCLoud ON/OFF FAILED: (error, privacy:.public)) } } self.initCor
Jan ’25
CoreData + CloudKit
I am having problems when I first loads the app. The time it takes for the Items to be sync from my CloudKit to my local CoreData is too long. Code I have the model below defined by my CoreData. public extension Item { @nonobjc class func fetchRequest() -> NSFetchRequest { NSFetchRequest(entityName: Item) } @NSManaged var createdAt: Date? @NSManaged var id: UUID? @NSManaged var image: Data? @NSManaged var usdz: Data? @NSManaged var characteristics: NSSet? @NSManaged var parent: SomeParent? } image and usdz columns are both marked as BinaryData and Attribute Allows External Storage is also selected. I made a Few tests loading the data when the app is downloaded for the first time. I am loading on my view using the below code: @FetchRequest( sortDescriptors: [NSSortDescriptor(keyPath: Item.createdAt, ascending: true)] ) private var items: FetchedResults var body: some View { VStack { ScrollView(.vertical, showsIndicators: false) { LazyVGrid(columns: columns, spacing: 40) { ForEach(items, id: .self) { item in
1
0
925
Jan ’25
Reply to CoreData + CloudKit
I'd firstly point you the following technotes, which I believe will give you the whole picture about how Core Data + CloudKit works: TN3163: Understanding the synchronization of NSPersistentCloudKitContainer TN3164: Debugging the synchronization of NSPersistentCloudKitContainer TN3162: Understanding CloudKit throttles Concretely to your questions: What are the solutions I have when the user first loads the app? How to force CoreData to query directly cloudKit? There is no API for an app to speed up the initial synchronization as of today. If there is a lot of data on the server, the synchronization will indeed take long time. I'd suggest that you file a feedback report against that. There is no API to force CoreData to import from CloudKit, and that is as-designed, as discussed in the technotes mentioned above. Does CoreData + CloudKit + NSPersistentCloudKitContainer will download the whole CloudKit database in my local, is that good???? When using NSPersistentCloudKitContainer
Jan ’25
Reply to How to let iCloud sync across the devices without launching the app at midnight?
Thanks for sharing. SwiftData + CloudKit is based on NSPersistentCloudKitContainer as of today, which doesn't do any synchronization if the app is not launched. Even if the app is running, it will be up to the system to decide when to synchronize data. There is no way for an app to force NSPersistentCloudKitContainer to synchronize with CloudKit. Best, —— Ziqiao Chen  Worldwide Developer Relations.
Jan ’25
Reply to CloudKit sync stopped working with error „You can't save and delete the same record"
You can't save and delete the same record Assuming that you are using Data + CloudKit, I am guessing that this can be triggered by your code and data. Consider the following configuration as an example: Delete Rule: cascade articleA.associatedArticles -> [articleB, articleC...] articleB.associatedArticles -> [articleA, articleC...] If you delete articleA, Core Data will delete articleB due to 1 and 2, and change articleB due to 3 at the same time. You can review your code to see if the above case can happen. When you use Core Data + CloudKit, NSPersistentCloudKitContainer configures and performs the CloudKit operations without any involvement of your code, and so it is worth filing a feedback report for the Core Data team to investigate why the case isn't handled – If you do so, please share your report ID here. Already have a mirrored relationship registered for this key Based on the (more) information you provided to DTS, this seems to indicate that you has a reflexive relationship (a relatio
Jan ’25
Reply to Recovering Customer's Data After iCloud Migration
@DTS Engineer We are not currently using any APIs specifically for iCloud account switches. Our app’s data is managed entirely through Core Data, backed by NSPersistentCloudKitContainer for synchronization with iCloud. When my colleague checked the CloudKit Console after logging into their iCloud account, they did not see the custom zone we use to store Core Data records. This absence has us concerned about whether the data is still recoverable. If the iCloud account is still active, should Core Data records managed via NSPersistentCloudKitContainer automatically sync back? Or does switching iCloud accounts result in the permanent deletion of associated Core Data records? Our plan is to recommend that the user logs back into their original iCloud account, ensures that iCloud is enabled for our app, and opens the app to allow time for the data to sync back. Is this the correct approach for recovering the data, or are there additional steps we should take? Any guidance would be greatly appreci
Jan ’25
Why did NSPersistentCloudKitContainer added CKAsset fields for each String in Core Data
Hi, I've been using Core Data + CloudKit via NSPersistentCloudKitContainer for several years now. Back then I just created my Core Data AND CloudKit fields by hand. Now the time has come for a little lightweight migration to a new Core Data model, let's say I just needed to add one String attribute. So I've done the Core Data local migration as usual, then added this to container code: try? persistentContainer.initializeCloudKitSchema(options: NSPersistentCloudKitContainerSchemaInitializationOptions()) Run. And everything worked great. but… Now I've noticed that CloudKit created new CKAsset fields for each String attribute that I had in Core Data (about 5 new CKAsset fields). Is this normal!? Why? ! Is it safe to deploy these changes to prod? ty. ChatGPT said: This field is used internally by CloudKit to handle large string values. If the string value is small enough, it is stored in the normal String field, but if it exceeds the size limit (about 1KB), the string is automatically stored as a CKAsset
1
0
836
Jan ’25