In xCode the following code moves a file from one directory to another or back again. It works.
When Cloudkit is activated, and the App Sandbox "User Selected File" is changed to Read/Write, the same code gives the error:
Error: “testFile.txt” couldn’t be moved because you don’t have permission to access “myData”.
The Cloud file management works as expected when it is activated, but I loose access to my local file system.
How can I access the local file system with Cloudkit activated?
@IBAction func myButton(_ sender: Any) {
var source:URL?
var target:URL?
let fm = FileManager.default
if fm.fileExists(atPath: "/Users/xxx/DocumentsLocal/testFile.txt") {
source = URL(fileURLWithPath: "/Users/xxx/DocumentsLocal/myData/testFile.txt")
target = URL(fileURLWithPath: "/Users/xxx/DocumentsLocal/testFile.txt")
} else {
target = URL(fileURLWithPath: "/Users/xxx/DocumentsLocal/myData/testFile.txt")
source = URL(fileURLWithPath: "/Users/xxx/DocumentsLocal/testFile.txt")
}
do{
try fm.moveItem(at: source!, to: target!)
print("Transfer successful\n")
} catch let error {
print("Error: \(error.localizedDescription)")
}
}