|
I am using an NSPersistentCloudKitContainer to sync data. If a user runs out of storage space, or disables iCloud syncing for my app, it seems like it would be best to switch to just using a local store. However, I can't find any guidance on how to do this. Is this something that I should just let the NSPersistentCloudKitContainer handle for me? Or is there another solution? For reference, this is how I am setting up the container in my app delegate (the default setup):
|
|
Hi @wbrennan899 , I am working thru this now for Core Data. I do have this for just CloudKit on another app so hopefully this helps. First, it comes down to use case. In my other app where it is just CK and no CD I use it track 'free usage' so that it comes across all devices. Here is the error handling on the completion block for save I use but pretty much lock access if I can't track the usage.
I am not sure yet on how Core Data reports this because I'm not sure how to induce these conditions with Core Data but hoping any answer you get addresses that. In my current use case with Core Data I think I should notify the user that they can't share info across devices as a gentle reminder to change their settings. Just not sure if this same logic above works. Thanks |
|
UPDATE: This is not a good solution. You cannot toggle Also in this case:
All of the local user data is lost, which was not my intention. ORIGINAL: I figured it out! This thread was helpful: https://developer.apple.com/forums/thread/118924 This solution should allow me to start with iCloud sync off, then I should be able to toggle syncing on/ off it by toggling
|
|
@wbrennan899 Hey Will, thanks for posting all of this. I am also encountering data loss through these four steps you've mentioned. Could you tell me what exactly you did, to fix it? Thanks! Best, Kai |
|
Update: I have been able to fix it. I think it's exactly as you described. Having my persistence container always initialized without CloudKit enabled (with default NSPersistentContainer or description.cloudKitContainerOptions = nil) made it work. If the user want to use cloudKit, then I will update my container right away with consideration of the device settings. A snipped:
Thank you:) |
SPONSORED Alex is the iOS & Mac developer’s ultimate AI assistant. It integrates with Xcode, offering a best-in-class Swift coding agent. Generate modern SwiftUI from images. Fast-apply suggestions from Claude 3.5 Sonnet, o3-mini, and DeepSeek R1. Autofix Swift 6 errors and warnings. And so much more. Start your 7-day free trial today!
Sponsor Hacking with Swift and reach the world's largest Swift community!
This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.