У меня есть приложение, и в приложении делегат у меня есть код для копирования файла db в папку документов, но он не работает, я не знаю почему, потому что он работал раньше и выдает следующую ошибку, пожалуйста, посмотрите и надеюсь, что вы сможетенайти что-то.Спасибо
// Creates a writable copy of the bundled default database in the application Documents directory.
- (void) createDatabaseExecutableFile {
// First, test for existence.
BOOL _successDB;
BOOL _successConfig;
NSFileManager* _fileManager = [NSFileManager defaultManager];
NSError* _error;
NSArray* _paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString* _documentsDirectory = [_paths objectAtIndex:0];
NSString* _writableDBPath = [_documentsDirectory stringByAppendingPathComponent:@"turfnutritiontool_ver.db"];
NSString* _writableConfigPath = [_documentsDirectory stringByAppendingPathComponent:@"Configuration.plist"];
_successDB = [_fileManager fileExistsAtPath:_writableDBPath];
_successConfig = [_fileManager fileExistsAtPath:_writableConfigPath];
if (_successDB && _successConfig) {
return;
}
// The writable database does not exist, so copy the default to the appropriate location.
NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"turfnutritiontool_ver.db"];
NSString *defaultConfigPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Configuration.plist"];
_successDB = [_fileManager copyItemAtPath:defaultDBPath toPath:_writableDBPath error:&_error];
_successConfig = [_fileManager copyItemAtPath:defaultConfigPath toPath:_writableConfigPath error:&_error];
if (!_successDB || !_successConfig) {
NSAssert1(0, @"Failed to create writable database file with message '%@'.", [_error localizedDescription]);
}
}
Это ошибка:
2012-04-02 13:52:01.162 TurfNutritionTool_ver_5.1[2379:b903] *** Assertion failure in -[AppDelegate createDatabaseExecutableFile], /Development/TurfNutritionTool_IOS_5.1/TurfNutritionTool/AppDelegate.m:188
2012-04-02 13:52:01.165 TurfNutritionTool_ver_5.1[2379:b903] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Failed to create writable database file with message 'The operation couldn’t be completed. File exists'.'
*** Call stack at first throw:
(
0 CoreFoundation 0x0179a5a9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x018ee313 objc_exception_throw + 44
2 CoreFoundation 0x01752ef8 +[NSException raise:format:arguments:] + 136
3 Foundation 0x011fc3bb -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 116
4 TurfNutritionTool_ver_5.1 0x00003fef -[AppDelegate createDatabaseExecutableFile] + 831
5 TurfNutritionTool_ver_5.1 0x00003486 -[AppDelegate application:didFinishLaunchingWithOptions:] + 86
6 UIKit 0x009f9c89 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1163
7 UIKit 0x009fbd88 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 439
8 UIKit 0x00a06617 -[UIApplication handleEvent:withNewEvent:] + 1533
9 UIKit 0x009feabf -[UIApplication sendEvent:] + 71
10 UIKit 0x00a03f2e _UIApplicationHandleEvent + 7576
11 GraphicsServices 0x01e21992 PurpleEventCallback + 1550
12 CoreFoundation 0x0177b944 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
13 CoreFoundation 0x016dbcf7 __CFRunLoopDoSource1 + 215
14 CoreFoundation 0x016d8f83 __CFRunLoopRun + 979
15 CoreFoundation 0x016d8840 CFRunLoopRunSpecific + 208
16 CoreFoundation 0x016d8761 CFRunLoopRunInMode + 97
17 UIKit 0x009fb7d2 -[UIApplication _run] + 623
18 UIKit 0x00a07c93 UIApplicationMain + 1160
19 TurfNutritionTool_ver_5.1 0x00002ddd main + 125
20 TurfNutritionTool_ver_5.1 0x00002d55 start + 53
21 ??? 0x00000001 0x0 + 1
)
terminate called throwing an exception(lldb)