如何找到设备上的当前.sqlite文件(iPad)

问题描述:

我需要查找当前的.sqlite文件位置以进行备份;我该怎么做呢?这是代码我有,它返回 “找不到文件”:如何找到设备上的当前.sqlite文件(iPad)

// find current directory for saori.sqlite 
NSString *coreDataStorePath = [self createCoreDataStorePath]; 
// sqlite store setup 
NSString *storePath = [coreDataStorePath stringByAppendingPathComponent:@"BookstoreInventoryManager.sqlite"]; // Application Support/SalonBook/saori.sqlite/saori.sqlite 
NSLog(@"\n\nBACKUP - storePath: %@",storePath); 

NSFileManager *fileManager = [NSFileManager defaultManager]; 
if ([fileManager fileExistsAtPath: storePath]) 
    [MagicalRecord cleanUp]; // set stack, etc to 'nil' 
else { 
    NSLog(@"\n\n-->BookstoreInventoryManager files not found"); // log message "unable to find sqlite files 
    return; 
} 

这里是createCoreDataStorePath代码:我已经看过谷歌和SO

-(NSString *)createCoreDataStorePath { 

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES); 
NSString *applicationSupportDirectory = [paths firstObject]; 

NSString *coreDataStorePath = [applicationSupportDirectory stringByAppendingPathComponent:@"/books"]; 
NSLog(@"\n\ncoreDataStorePath: %@", coreDataStorePath); 

return coreDataStorePath; 

}

,并没有在那里找到我的答案。

-(NSString *)applicationDocumentsDirectory { 

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSString *basePath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil; 
return basePath; 

}

它给了我店里的实际网址...谢谢你Larme您的回复:

+0

什么是'coreDataStorePath'?你如何保存/检索它?用'NSApplicationSupportDirectory'? – Larme

我使用此代码想通了......。 SD