mardi 15 décembre 2015

Add Pre populated sqlite debase in iOS App

In My Application I am getting data (sql Table data) from server and store it in sqlite tables.which require lot of user data so that I am try to do run app on simulator and get that database file,now I am trying to do add this database file in to my project and copied it to my sqlite table(I don't know its right or wrong).it will not copied to my sqlite database.when I add this file in Xcode this looks likeenter image description here

then I am using this code to copy this db

NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir = [paths objectAtIndex:0];

NSString *dbPath = [documentsDir stringByAppendingPathComponent:@"moviedbl.data"];

if([fileManager fileExistsAtPath:dbPath]==NO){

    NSString *defaultDBPath = [[NSBundle mainBundle] pathForResource:@"mylocaldb" ofType: @"sqlite"];
   BOOL success = [fileManager copyItemAtPath:defaultDBPath toPath:dbPath error:&error];

    if(!success){
        NSAssert1(0, @"Failed to create writable database file with message '%'.", [error localizedDescription]);
    }
}

then it will gives me error Source path is nil. Please suggest what should I do.Is this right way to do it.Thanks

Aucun commentaire:

Enregistrer un commentaire