2016-11-28 40 views
1

我需要查找當前的.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

回答

相關問題