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

Community
  • 1
  • 1
Sanju
  • 1,148
  • 11
  • 26
  • Do you store the file in the Documents folder in your app? Show some relevant code. – rmaddy Dec 17 '15 at 15:13
  • i have edited the code please check once, I need to add any code for to View Sqlite File ?? @rmaddy – Sanju Dec 18 '15 at 09:13

1 Answers1

2

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

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

You want NSDocumentDirectory.

trojanfoe
  • 120,358
  • 21
  • 212
  • 242
  • Do not forget to turn off iTunes File Sharing before uploading to App Store. Otherwise your app will be rejected. – Arik Segal Jul 19 '16 at 07:17