无法在iTunes中看到SQLite文件

时间:2015-12-17 13:43:35

标签: ios objective-c iphone sqlite

- (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]);
    }
}

我需要为View Sqlite File添加任何代码吗?

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

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

推荐链接: How to enable file sharing for my app?UIFileSharingEnabled has no effect

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

1 个答案:

答案 0 :(得分:2)

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

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

您想要NSDocumentDirectory