开发者

SQLite wrapper in iOS?

开发者 https://www.devze.com 2023-02-28 12:19 出处:网络
I have an iPhone app that stores information to a SQLite database. It works splendid on my phone as well as my brothers. Stuff get\'s written to it and it can read from it. However, when running it on

I have an iPhone app that stores information to a SQLite database. It works splendid on my phone as well as my brothers. Stuff get's written to it and it can read from it. However, when running it on other people's phone's, it just crashes. Why?

I am using Matteo Bertozzi's SQLite wrapper (put files in the classes folder and linked to them in my .h like this: #import 开发者_如何学Go"Sqlite.h")

I have also imported the libsqlite3.dylib to my project.

Declared my SQLite database like this in my .h as well: Sqlite *database;

Set up my database like this:

if (database == nil) {
// Set up database connection
NSString *myDBTwo = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"flashpics.db"];
database = [[Sqlite alloc] init];
[database open:myDBTwo];
}

And call a query like this (none of my variables are nil) :

[database executeNonQuery:@"INSERT INTO images (id, thumbnail, album, caption) VALUES (?, ?, ?, ?)", photoID, thumbnailLocation, photoAlbumID, photoCaption];

However it crashes on my friend's phone and returns EXC_BAD_ACCESS when trying to read it.. Nothing happens when you try to write to it.

Please help! Thanks

PS: Here's the link to the wrapper: http://th30z.blogspot.com/2008/11/objective-c-sqlite-wrapper_8445.html

Edit #1: Here's some of the errors I get when loading the app. Maybe this is causing it? Or it's not linking to the correct library?

warning: Unable to read symbols for /Developer/Platforms/iPhoneOS.platform/DeviceSupport/4.2.1 (8C148)/Symbols/usr/lib/info/dns.so (file not found).

And here's what I get when I do the action that makes it crash.

Program received signal:  “EXC_BAD_ACCESS”.
warning: Unable to read symbols for /Developer/Platforms/iPhoneOS.platform/DeviceSupport/4.2.1 (8C148)/Symbols/Developer/usr/lib/libXcodeDebuggerSupport.dylib (file not found).


The problem is that you are trying to write to the resources folder in your app bundle, which is read only on a non-jailbroken system, due to safety/security reasons, you have to create the database in the documents folder, so you change your code to this...

EDIT: SORRY I pasted the WRONG code, here is the fixed version.

 NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSString *myDBTwo = [[paths objectAtIndex:0]stringByAppendingPathComponent:@"flashpics.db"];


RTS is right, you have to copy it over to the Documents directory (or someplace similar) that is writable.

The reason it worked on your devices? If I had to guess I'd say you're both jailbroken and that notion of a code-signed bundle that cannot be modified isn't really enforced.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号