Friday, 15 February 2013

osx - Allowed App file locations - with-or-without Sandboxing -



osx - Allowed App file locations - with-or-without Sandboxing -

ok, question straightforward cannot find 1 straightforward answer. so, i'd glad if help.

what want :

a place (either on 10.6 - without sandboxing - or 10.7-and-later, sandboxing) app can freely write data.

in few words :

i want know if there's scheme function (e.g. nshomedirectory()) points safe location me write (os x version shouldn't matter).

ok, here am, answering own question.

so, if need access application support directory (and create if doesn't exist), no matter if we're on 10.6 (without sandboxing enabled) or 10.7+?

here's universal solution (i myself wrote category on nsfilemanager that, simple function or macro do...) :

interface :

// nsfilemanager+paths.h #import <foundation/foundation.h> @interface nsfilemanager (paths) + (nsstring*)applicationsupportdirectory; @end

implementation :

// nsfilemanager+paths.m #import "nsfilemanager+paths.h" @implementation nsfilemanager (paths) + (nsstring*)applicationsupportdirectory { nserror *error; homecoming [[[nsfilemanager defaultmanager] urlfordirectory:nsapplicationsupportdirectory indomain:nsuserdomainmask appropriateforurl:nil create:yes error:&error] path]; } @end

rather simple, huh?

hint : please have @ 2 comments below fix reply more elegant solution.

osx cocoa sandbox

No comments:

Post a Comment