Best way to use iCloud Documents Storage
I succeeded in uploading a file from my app to icloud by referring to the link above.
But I can't upload files since I deleted the app and reinstalled it
Below is the error log
Error Domain=NSCocoaErrorDomain Code=512 "Could not copy 'backup.db' to 'Documents'." UserInfo={NSSourceFilePathErrorKey=/var/mobile/Containers/Data/Application/7B27D1E4-FE7F-4541-8E04-68CCB2A894D4/Documents/backup.db, NSUserStringVariant=(
Copy
), NSDestinationFilePath=/private/var/mobile/Library/Mobile Documents/iCloud~com~sinwho~CheckDay/Documents/backup.db, NSFilePath=/var/mobile/Containers/Data/Application/7B27D1E4-FE7F-4541-8E04-68CCB2A894D4/Documents/check_day.db, NSUnderlyingError=0x2804517d0 {Error Domain=NSPOSIXErrorDomain Code=20 "Not a directory"}}
Try adding the following to Info.plist
<key>NSUbiquitousContainers</key>
<dict>
<key>iCloud.com.sinwho.CheckDay</key>
<dict>
<key>NSUbiquitousContainerIsDocumentScopePublic</key>
<true/>
<key>NSUbiquitousContainerName</key>
<string>MyApp</string>
<key>NSUbiquitousContainerSupportedFolderLevels</key>
<string>Any</string>
</dict>
</dict>
I also tried startAccessingSecurityScopedResource. No error occurs, but the file is not actually copied.
I also changed the CFBundleVersion
Is there any way to solve this problem?
if DocumentsDirectory.iCloudDocumentsURL!.startAccessingSecurityScopedResource() {
try fileManager.copyItem(at: DocumentsDirectory.dbFileURL.appendingPathComponent(file), to:
DocumentsDirectory.iCloudDocumentsURL!.appendingPathComponent(file))
}
DocumentsDirectory.iCloudDocumentsURL!.stopAccessingSecurityScopedResource()