views:

570

answers:

2

Hello Brad,

I have an application which sets an web image to the background of the homepage.From next time it loads the homepage background from web as my application stores just the name with the address.This is my code:

Sqlite *sqlite = [[Sqlite alloc] init];

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, SUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *writableDBPath = [documentsDirectory stringByAppendingPathComponent:@"Database.db"];

if (![sqlite open:writableDBPath])
    return;
NSURL *url = [NSURL URLWithString:@"http://mmabigshow.com/app/admin/ring_girl_demo.php"];
NSString *greeting = [[NSString alloc] initWithContentsOfURL:url];
NSString *string1 = @"";

string1 = [NSString stringWithFormat:@"UPDATE mma_bg_image SET image='%@' where id='1';", greeting];

What I want to do is, that when I set some image as background it should be stored as UIImage object in the local database of the phone so that it will load faster from next time onwards. Should I use Sqlite? Please paste me the total source code of the process.

Thanks in advance

Rohit Y

+11  A: 

Why don't you just store the image on the filesystem?
Of course you could store it into the DB but it wouldn't make your app faster. You would have to encode the file using NSData before inserting it and decode it before displaying it.
I would store the file on the filesystem and keep just the path in the DB.

Edit:
Yours truly, Brad

weichsel
+3  A: 

Hello Rohit,

I provide code for storing UIImages to, and loading them from, an SQLite database in this answer.

Sincerely, Another Brad

Brad Larson