Until a few days ago, I had a bit of code that could download a file from elsewhere to my home drive, "Users/eric".
Today, the code downloads the file to "locat", but the following no longer works
let _ = try fileManager.copyItem(atPath: locat, toPath: "/Users/eric/file.txt" )
After a careful search, I've changed the network to allow Network connections, and set User Selected and Downloads Folder to Read/Write without any luck.
I am using Catalina and SwiftUI on a recent Mac (2023). As well, it was working just a few days ago. Any ideas or pointers?
It sounds like your app has App Sandbox enabled (check for this in the Signing & Capabilities editor). If so, it won’t be able to read from or write to arbitrary locations outside of its sandbox.
As to what you should do about that, it depends on your goals:
-
If you’re planning to ship your app to the Mac App Store then sandboxing is required. In that case we should have a deeper conversation about the design of your app.
-
If not, disabling App Sandbox is a practical option.
-
Whether you should or not depends on a lot of factors. One option is to leave App Sandbox and use temporary exception entitlements to go beyond the sandbox. See The Case for Sandboxing a Directly Distributed App.
-
OTOH, if you’re just building a quick test app, it’s often best to just disable the sandbox.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"