无法创建可写数据库文件

时间:2016-02-10 07:09:21

标签: ios objective-c

2016-02-10 12:35:14.524 FlightTableView[2448:127703] *** Assertion failure in -[AppDelegate copyDatabaseIfNeeded], /Volumes/Data/Nasrin/FlightTableView/FlightTableView/AppDelegate.m:30
2016-02-10 12:35:14.528 FlightTableView[2448:127703] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Failed to create writable database file with message 'The file “Airports.sqlite3” couldn’t be opened because there is no such file.'.'
*** First throw call stack:
(
    0   CoreFoundation                      0x00000001026c1e65 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x0000000102138deb objc_exception_throw + 48
    2   CoreFoundation                      0x00000001026c1cca +[NSException raise:format:arguments:] + 106
    3   Foundation                          0x0000000101d844de -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 198
    4   FlightTableView                     0x0000000101b1529c -[AppDelegate copyDatabaseIfNeeded] + 668
    5   FlightTableView                     0x0000000101b15439 -[AppDelegate application:didFinishLaunchingWithOptions:] + 89
    6   UIKit                               0x0000000102a661f1 -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 272
    7   UIKit                               0x0000000102a67397 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 3415
    8   UIKit                               0x0000000102a6dcc6 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1760
    9   UIKit                               0x0000000102a6ae7b -[UIApplication workspaceDidEndTransaction:] + 188
    10  FrontBoardServices                  0x000000010535c754 -[FBSSerialQueue _performNext] + 192
    11  FrontBoardServices                  0x000000010535cac2 -[FBSSerialQueue _performNextFromRunLoopSource] + 45
    12  CoreFoundation                      0x00000001025eda31 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    13  CoreFoundation                      0x00000001025e395c __CFRunLoopDoSources0 + 556
    14  CoreFoundation                      0x00000001025e2e13 __CFRunLoopRun + 867
    15  CoreFoundation                      0x00000001025e2828 CFRunLoopRunSpecific + 488
    16  UIKit                               0x0000000102a6a7cd -[UIApplication _run] + 402
    17  UIKit                               0x0000000102a6f610 UIApplicationMain + 171
    18  FlightTableView                     0x0000000101b18acf main + 111
    19  libdyld.dylib                       0x00000001040b992d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

(void)copyDatabaseIfNeeded方法如下。

   NSFileManager *fileManager = [NSFileManager defaultManager]; 
   NSError *error; NSString *dbPath = [self getDBPath]; 
   BOOL success = [fileManager fileExistsAtPath:dbPath]; 
   if(!success) 
       { 
          NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Airports.sqlite"]; 
          success = [fileManager copyItemAtPath:defaultDBPath toPath:dbPath error:&error]; 
   if (!success) NSAssert1(0, @"Failed to create writable database file with message '%@'.", [error localizedDescription]);

0 个答案:

没有答案