Hi there,
I am attempting to move a file to the documents folder programmatically within my iOS app. See below for a code snippet, nothing crazy just simple FileManager interactions.
func moveZip(sourceUrl: URL) -> URL? {
let destinationUrl: URL = getDocumentsDirectory().appendingPathComponent(sourceUrl.lastPathComponent)
do {
if FileManager.default.fileExists(atPath: destinationUrl.path) {
try FileManager.default.removeItem(atPath: destinationUrl.path)
}
try FileManager.default.moveItem(atPath: sourceUrl.path, toPath: destinationUrl.path)
return destinationUrl
} catch {
print(error.localizedDescription)
return nil
}
}
sourceUrl = file:///private/var/mobile/Containers/Shared/AppGroup/XXXXXXXXXXXXXXXXXXXXX/File%20Provider%20Storage/Work/file.zip
destinationUrl =
file:///var/mobile/Containers/Data/Application/XXXXXXXXXXXXXXXXXXXXX/Documents/file.zip
Once I hit the line try FileManager.default.moveItem
call I fail out with the following error:
“file.zip” couldn’t be moved because you don’t have permission to access “Documents”.
I believe I'm accessing everything correctly and have tried to dig into any possible info.plst access privileges but I haven't found anything yet.
Running Xcode Version 13.0 beta and targeting an iPhone 11 Pro Max running iOS v14.7.
Any help is appreciated!
Thanks!
Is it the documents folder of the app ?
Have a look at this: https://developer.apple.com/forums/thread/76609