I am trying to figure out how to rename an instance of a subclass of UIDocument in an iCloud folder. I tried to save the document with a new url ...
func renameDocument(to name: String) { let targetURL = document.fileURL.deletingLastPathComponent().appendingPathComponent(name) .appendingPathExtension("<extension>") document.save(to: targetURL, for: .forCreating) { success in guard success else {
... but this is not with ...
Error Domain=NSCocoaErrorDomain Code=513 ""<new-file-name>" couldn't be moved because you don't have permission to access "<folder>"." UserInfo={NSSourceFilePathErrorKey=/private/var/mobile/Containers/Data/Application/1A9ACC2B-81EF-4EC9-940E-1C129BDB1914/tmp/(A Document Being Saved By My App)/<new-file-name>, NSUserStringVariant=( Move ), NSDestinationFilePath=/private/var/mobile/Library/Mobile Documents/com~apple~CloudDocs/<folder>/<new-file-name>, NSFilePath=/private/var/mobile/Containers/Data/Application/1A9ACC2B-81EF-4EC9-940E-1C129BDB1914/tmp/(A Document Being Saved By My App)/<new-file-name>, NSUnderlyingError=0x1c4e54280 {Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted"}}
... and just a step ...
func renameDocument(to name: String) { let targetURL = document.fileURL.deletingLastPathComponent().appendingPathComponent(name) .appendingPathExtension("<extension>") do { try FileManager.default.moveItem(at: document.fileURL, to: targetURL) } catch {
... which does not work with ...
Error Domain=NSCocoaErrorDomain Code=513 ""<old-file-name>" couldn't be moved because you don't have permission to access "<folder>"." UserInfo={NSSourceFilePathErrorKey=/private/var/mobile/Library/Mobile Documents/com~apple~CloudDocs/<folder>/<old-file-name>, NSUserStringVariant=( Move ), NSDestinationFilePath=/private/var/mobile/Library/Mobile Documents/com~apple~CloudDocs/<folder>/<new-file-name>, NSFilePath=/private/var/mobile/Library/Mobile Documents/com~apple~CloudDocs/<folder>/<old-file-name>, NSUnderlyingError=0x1c4c4d8c0 {Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted"}}
Both of these features are great for local files, and renaming iCloud files works fine in the UIDocumentBrowserViewController root view UIDocumentBrowserViewController .
My guess is that somewhere there is some kind of permission that allows the application to write to iCloud folders.
For information info.plist contains all of the following keys ...
LSSupportsOpeningDocumentsInPlaceNSExtensionFileProviderSupportsEnumerationUISupportsDocumentBrowser
source share