问题描述
|
Apple在本文档中以及此处和此处都告诉您这样做。
我不希望重新发明轮子,并且肯定有人已经这样做了,但是我对Google并不幸运。有人知道一个博客指出如何做到这一点吗?
问题是,我必须使用“库”中的应用程序捆绑包ID名称创建此目录,但前提是该目录不存在。
解决方法
我认为这是您要寻找的:
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];
}