I have created database and table through sqlite3 using termnal on macbook,then deploy it on my iphone's application.Its working fine with simulator i.e inserting & retriving the values from table. but when i install it on real iphone it is not working, why? I think it can not get the path of databse,then how can i do that?? plz help me i am new in iphone development.
+1
A:
Are you leaving the database in the base app path?
Because if you are, the actual hardware won't allow you to write to files in that directory, just read. To write to the database, you will first have to copy it to an accessible directory.
I'm doing something similar to this (where filename is an NSString containing the name of the database file):
NSArray *docPaths =
NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docPath = [docPaths objectAtIndex:0];
NSString *fullName = [docPath stringByAppendingPathComponent:fileName];
NSFileManager *fm = [NSFileManager defaultManager];
if (![fm fileExistsAtPath:fullName])
{
NSString *path = [[NSBundle mainBundle] bundlePath];
NSString *defaultName = [path stringByAppendingPathComponent:fileName];
[fm copyItemAtPath:defaultName toPath:fullName error:NULL];
}
Basically, check if the file already exists and copy it from the base bundlePath if it doesn't.
toast
2009-04-15 13:30:07