Reputation: 27
I'm implementing a feature to upload and download files from iCloud in my app. Everything is working as expected, however, I noticed that if I delete the app folder from iCloud drive (as an end-user) this completely breaks the functionality.
Trying to recreate the folder with:
let containerURL = FileManager.default.url(forUbiquityContainerIdentifier: nil)?.appendingPathComponent("Documents")
FileManager.default.createDirectory(at: containerURL, withIntermediateDirectories: true, attributes: nil)
Fails with error: "You don't have permission to save the file "Documents" in the folder "container_name"
Trying to upload the file directly:
FileManager.default.copyItem(at: localFilePath, to: iCloudFilePath)
Fails with error: "The file "file_name" doesn't exist".
The only way I found to fix the issue is to create a new container. Obviously, this will be of no use after the app is published.
I did a test with an existing popular app (HealthFit) and can see the same behaviour - after I deleted HealthFit folder from iCloud, the app can no longer upload even after re-installing it. It shows the same error as my app "The file "file_name" doesn't exist" when trying to upload.
Any ideas on how to fix this in production? App folders are in no way protected or hidden in the iCloud and would be pretty easy for users to delete either by accident or thinking it's not needed...
Upvotes: 0
Views: 20