Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

1 Answer

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

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

You want NSDocumentDirectory.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...