Java goes AppStore?

Marco Dinacci marco.dinacci at gmail.com
Wed Sep 19 01:44:57 PDT 2012


Hi Paul,

> Just read your very useful blog, the bit about the sandbox is completely new
> to me. My application currentlyly stores file in Library/Preferences/MyApp
> and Library/Logs/MyApp, so are you saying this concept no longer applies and
> everything should go into
> Library/Containers/Myapp ?

Mostly correct. If you sandbox the app you won't be able to write into
those directories but you don't have to as the container also have a
Logs and Preferences directory.

You should obtain the directory to write to by using the Foundation
function NSSearchPathForDirectoriesInDomains:

NSArray *paths = NSSearchPathForDirectoriesInDomains(
                                NSLibraryDirectory,
                                NSUserDomainMask, YES);

if you call it when your app is in the sandbox it will return the
Library directory inside the container otherwise it will return the
path of the Library directory in the user home. For example, if your
app is called MyApp, the function will return an array containing an
NSString whose value is:

sandbox: ~/Library/Containers/com.foo.MyApp/Data/Library
outside: ~/Library

See ~/Library/Containers/com.apple.TextEdit/ for an example of what's
inside a sandbox container.

Of course if you don't want to go native you could hardcode the
container path (~/Library/Containers/com.foo.MyApp) in your app
although if Apple decides to change the location of the container your
app will stop working. You'll also have to detect whether you're in
the container or not to write to the correct Logs and Preferences
directory. I preferred to go with the native route.

> If so does it make sense to do this for a non Appstore version of the
> application as well or not

you should re-engineer the app in a way that you use the path returned
by NSSearchPathForDirectoriesInDomains as your "root" directory. Then
append Logs and Preferences as they both exist inside and outside the
container.

Best,
Marco


More information about the macosx-port-dev mailing list