Unable to see SQLite file in iTunes

2019-09-23 01:33发布

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

I need to add any code for to View Sqlite File ??

I tried by adding these in Plist: UIFileSharingEnabled, CFBundleDisplayName

How can i view my SQLIte file in iTunes ?

Referred links: How to enable file sharing for my app?, UIFileSharingEnabled has no effect

If i enabled iTunes file sharing option in my app to backup app data in PC, will appStore rejects the app ?

1条回答
放荡不羁爱自由
2楼-- · 2019-09-23 02:31

You are not creating the file in the Documents directory, but the Library directory:

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

You want NSDocumentDirectory.

查看更多
登录 后发表回答