Trouble accessing fileURL: Simulator to iPhone

Hi,

I'm having trouble accessing a file on my device. The file is saved to the Files App. On the simulator it runs without a hitch, but on my iPhone it crashes because it doesn't have permission to access the file, even though it created the file. I'm guessing there's probably something that needs setting, perhaps in the info.plist? Supports opening files in place is set to yes, so I've ruled that out as the problem. Any advice much appreciated.
How are you getting the URL to that file?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@apple.com"
Hi eskimo, I've discovered my error. I set "open document in place" to NO, and it now imports and processes without a problem.

I was using the guard statement below, and when it wasn't working I tried the do statement, which didn't work either. I haven't tried the guard statement yet to see if it works since changing the setting, but I suspect that it will.

I don't know why it wasn't working. I guess it has something to do with the url having private in its path. I've got some learning to do there.

"Failed reading from URL: file:///private/var/mobile/Containers/Shared/AppGroup/FC9D99"

var data = Data()
  do {
   data = try Data(contentsOf: url)
  }catch let error as NSError{
   print("Failed reading from URL: \(url), Error: " + error.localizedDescription)
  }
   
   
  //guard let data = try? Data(contentsOf: url) else { return "blah" }
BTW, the error basically said that the app "doesn't have permission to view the file". Is there a way to grant it permission? Having the app open up by tapping on the file is a very nice feature.
Trouble accessing fileURL: Simulator to iPhone
 
 
Q