xCode CloudKit activated and loose access to local files

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)")

}

}

>> When Cloudkit is activated, and the App Sandbox "User Selected File" is changed to Read/Write


Are you saying that when you activated CloudKit, you also turned on sandboxing at the same time? If so, then you lost the ability to read/write files at arbitrary user-visible locations. (You only have access to files that are "inside" your sandbox container, unless the user gives you explicit access to files outside.)


IOW, I wouldn't expect code like the above to work in a sandboxed app, because "DocumentsLocal" isn't (AFAIK) inside the sandbox container.

10Q the program works without error now that I turned off the Sandbox capability, leaving the iCloud capabilty activated. I'll play around with it some more.

Just a note: I had to turn off the Sandbox in the entitlements file as the turned-on capability ui Sandbox switch wouldn't function.

xCode CloudKit activated and loose access to local files
 
 
Q