4

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.

pjg
  • 565
  • 4
  • 19
  • If the app is sandboxed and the binary file is inside the sandbox you should be able to use FileManager to translate your relative path inside the sandbox – Joakim Danielson May 09 '19 at 11:43
  • 1
    not sure I get this suggestion. Is there a particular NSFileManager method you have in mind? – pjg May 12 '19 at 22:39

2 Answers2

1

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.

pjg
  • 565
  • 4
  • 19
0

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.

Kate Orlova
  • 3,225
  • 5
  • 11
  • 35