【问题标题】:How do I find the current .sqlite file on the device (iPad)如何在设备 (iPad) 上找到当前的 .sqlite 文件
【发布时间】:2017-04-12 10:41:31
【问题描述】:

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

//  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的代码:

-(NSString *)createCoreDataStorePath  {

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

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

return coreDataStorePath;

}

我查看了 Google 和 SO,但没有找到我的答案。

【问题讨论】:

  • 什么是coreDataStorePath?你如何保存/检索它?与NSApplicationSupportDirectory ?

标签: objective-c sqlite nsfilemanager magicalrecord


【解决方案1】:

我想通了...使用此代码:

-(NSString *)applicationDocumentsDirectory {

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

}

它给了我商店的实际 URL...谢谢你 Larme 的回复。标清

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-21
    • 2014-07-20
    • 1970-01-01
    相关资源
    最近更新 更多