这是我的代码:
- (void)copyFileIfNeeded
{
NSFileManager *fileManager= [NSFileManager defaultManager];
NSError *error;
NSString *filePath = [self getFile];
BOOL success = [fileManager fileExistsAtPath:filePath];
if ( !success )
{
NSString *defaultFilePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"BQWDatabase.db"];
success = [fileManager copyItemAtPath:defaultFilePath toPath:filePath error:&error];
}
}
- (NSString *)getFile
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir = [paths objectAtIndex:0];
return [documentsDir stringByAppendingPathComponent:@"BQWDatabase.db"];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
[self copyFileIfNeeded];
return YES;
}
但是 Documents 文件夹总是空的,我该如何解决这个问题?谢谢你。
编辑: