jeudi 22 octobre 2015

My sqlite database in db form not working on actual device but work fine in simulator

In my app I am read ,write and delete on sqlite database(in db form) and it work fine in simulator but not working in actual device(giving error "No such table found").I try very hard to look for solution but couldn't find one or may be i misread something.

My db is in the /users/My Name/library/developer/Core simulator/devices/devicen-id/data/application/app-id/documents/My database.

- (NSString *) getWritableDBPath {

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

}

I am confuse where did i need to copy my database while running in the actual iOS device and what is the core problem.Any help regarding this will be very helpful

-(void)createEditableCopyOfDatabaseIfNeeded

{

BOOL success;
NSFileManager *fileManager1 = [NSFileManager defaultManager];
NSError *error;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
                                                     NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *writableDBPath = [documentsDirectory stringByAppendingPathComponent:mydaatabase];
NSLog(@"=======%@", writableDBPath);

success = [fileManager1 fileExistsAtPath:writableDBPath];
if (success)
    return;

NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath]
                          stringByAppendingPathComponent:mydaatabase];
NSLog(@"=======%@", [NSBundle mainBundle]);

  success = [fileManager1 copyItemAtPath:defaultDBPath
                               toPath:writableDBPath
                                error:&error];


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

}

Aucun commentaire:

Enregistrer un commentaire