Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
276 views
in Technique[技术] by (71.8m points)

ios - Unable to see SQLite file in iTunes

- (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 ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

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

You want NSDocumentDirectory.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...