Платформа возвращает правильный путь к папке поддержки приложений, но в отличие от папки Documents
она не создается по умолчанию.
Используйте альтернативный API NSFileManager
, который способен неявно создавать папку
- (NSURL*)applicationDataDirectory {
NSFileManager* sharedFM = [NSFileManager defaultManager];
NSURL* appSupportDir = [sharedFM URLForDirectory:NSApplicationSupportDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:YES error:nil];
// add the app's bundle ID to it to specify the final directory.
NSString* appBundleID = [[NSBundle mainBundle] bundleIdentifier];
return [appSupportDir URLByAppendingPathComponent:appBundleID];
}
Имейте в виду, что вы также несете ответственность за создание подпапки.
- (NSURL*)applicationDataDirectory {
NSFileManager* sharedFM = [NSFileManager defaultManager];
NSURL* appSupportDir = [sharedFM URLForDirectory:NSApplicationSupportDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:YES error:nil];
// add the app's bundle ID to it to specify the final directory.
NSString* appBundleID = [[NSBundle mainBundle] bundleIdentifier];
NSURL* appDirectory = [appSupportDir URLByAppendingPathComponent:appBundleID];
if (![appDirectory checkResourceIsReachableAndReturnError:nil]) {
[sharedFM createDirectoryAtURL:appDirectory withIntermediateDirectories:NO attributes:nil error:nil];
}
return appDirectory;
}