dontWatchMyProfile
dontWatchMyProfile

Reputation: 46370

How to create a private directory inside the Library directory and give it the name of the application’s bundle ID?

Apple is telling to do so in this document over here, and here.

I'd hate to re-invent the wheel and am sure someone did this already, but I wasn't lucky with Google. Does someone know a blog that points out how to do exactly that?

The problem is, I must create this directory with the app bundle ID name inside Library but only if it does not exist.

Upvotes: 3

Views: 421

Answers (1)

jaminguy
jaminguy

Reputation: 25930

I think this is what you are looking for:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
NSString *libraryPath = [paths objectAtIndex:0];
NSString *bundlePath = [libraryPath stringByAppendingPathComponent:[[NSBundle mainBundle] bundleIdentifier]];
if(![[NSFileManager defaultManager] fileExistsAtPath:bundlePath]) {
    [[NSFileManager defaultManager] createDirectoryAtPath:bundlePath withIntermediateDirectories:YES attributes:nil error:NULL];
}

Upvotes: 5

Related Questions