I did put my Core-Data-File into a subdirectory of the library directory.
By now I regret this decision. In the next version of my app the database will be accessible for the user again. I will rename it into database.sqlite and put a FAQ entry on my support page which tells the user the purpose of that file.
99.9% of the crashes that occur to my app occur because the database got corrupted in some way. And they can't send me that file, because they can't access it. So I can't find out what went wrong.
This is the code I used to access the private directory. It's in the LibraryDirectory, so iTunes will back it up automatically.
+ (NSString *)createAndReturnDirectory:(NSString *)path {
BOOL isDirectory = NO;
if ([[NSFileManager defaultManager] fileExistsAtPath:path isDirectory:&isDirectory]) {
if (isDirectory)
return path;
NSError *error = nil;
if (![[NSFileManager defaultManager] removeItemAtPath:path error:&error]) {
// do something.
return nil;
}
}
NSError *error = nil;
if (![[NSFileManager defaultManager] createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:&error]) {
// do something.
return nil;
}
return path;
}
+ (NSString *)applicationPrivateDocumentsDirectory {
NSString *libraryPath = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) lastObject];
NSString *path = [libraryPath stringByAppendingPathComponent:@"Private Documents"];
return [self createAndReturnDirectory:path];
}