【问题标题】:Unable to see SQLite file in iTunes在 iTunes 中看不到 SQLite 文件
【发布时间】:2016-03-24 00:15:18
【问题描述】:
- (void) copyDatabaseIfNeeded
{  
    BOOL success;
    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSError *error;
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *writableDBPath = [documentsDirectory stringByAppendingPathComponent:ABC.Sqlite];
    success = [fileManager fileExistsAtPath:writableDBPath];
    if (success) return;
    // The writable database does not exist, so copy the default to the appropriate location.
    NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:ABC.Sqlite];
    success = [fileManager copyItemAtPath:defaultDBPath toPath:writableDBPath error:&error];
    if (success)
    {
        NSURL *url=[NSURL URLWithString:WSURL2];

    } else
    {
        NSLog(@"Failed to create writable database file with message '%@'.", [error localizedDescription]);
    }
}

我需要添加任何代码来查看 Sqlite 文件??

我尝试在 Plist 中添加这些:UIFileSharingEnabledCFBundleDisplayName

如何在 iTunes 中查看我的 SQLite 文件?

参考链接: How to enable file sharing for my app?, UIFileSharingEnabled has no effect

如果我在我的应用中启用了 iTunes 文件共享选项来备份 PC 中的应用数据,appStore 会拒绝该应用吗?

【问题讨论】:

  • 您是否将文件存储在应用程序的 Documents 文件夹中?显示一些相关代码。
  • 我已经编辑了代码请检查一次,我需要添加任何代码来查看 Sqlite 文件?? @rmaddy

标签: ios objective-c iphone sqlite


【解决方案1】:

您不是在 Documents 目录中创建文件,而是在 Library 目录中:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
//                                                   ^^^^^^^^^^^^^^^^^^

你想要NSDocumentDirectory

【讨论】:

  • 在上传到 App Store 之前不要忘记关闭 iTunes 文件共享。否则您的应用将被拒绝。
猜你喜欢
  • 2016-09-25
  • 1970-01-01
  • 2015-12-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多