Reputation: 585
I am trying to write an import of a 3rd party file format in my macOS sandboxed app. The file the user opens is a Json document, and inside this document is a url pointing to some required external data file. In this case it is the relative path to a local binary data file. I can create an absolute path to this file but I cannot open it with [NSData datawithcontentsoffile: path] because my app is sandboxed (on macOS App Store). If I turn off sandbox then I can open the external binary file.
What are some good strategies to open the external file in a sand boxed app? I’m thinking of opening a second nsopenpanel and asking the user to select the other file, but that seems awkward.
Upvotes: 4
Views: 226
Reputation: 585
I found no solution other than to open a second nsopenpanel and ask the user to select the folder containing the json document. Once I had permission for the folder I could open any file given in the json document as long as it is in the same folder or subfolders of the json document.
Upvotes: 1
Reputation: 3283
There is only one difference between a sandboxed app and not I can think of - if an app is sandboxed then the home directory points to the app’s sandbox, otherwise it points to the user’s home directory on the file system. Therefore, when creating a file path consider using URLsForDirectory:inDomains: method of NSFileManager class returning a directory’s location.
Upvotes: 0