1

Hey All, I am thinking to save the data offline so that user can access the data on the iPhone when there is no internet connectivity. Can you please suggest an easy way to save the data for offline access. In my case I just need to save the rss feed so that whenever my service fails to pull the latest rss feed it should show the one that is present on phone.

Please help me guys!!! Thanks for your time.

racharambola
  • 417
  • 1
  • 8
  • 26

2 Answers2

1

You might want to use SQLite to save the data when the user is online. See this tutorial for implementing SQLite. If you haven't used it before SQLite stores it's database in a single file which you can use with the iPhone SDK.

You could also look into using Core Data to store information but I have no experience with this.

EDIT: This tutorial is probably better. It was the one I used when first using SQLite on the iPhone.

Community
  • 1
  • 1
ingh.am
  • 25,981
  • 43
  • 130
  • 177
  • The trend is towards Core Data, but the suggestion for SQLite is still valid. – KevinDTimm Nov 02 '10 at 15:52
  • It depends really. I never went down the Core Data route because everything I've developed on the iPhone has been developed for other platforms. SQLite is generally cross-compatible these days! Not on all of them mind!! – ingh.am Nov 02 '10 at 15:55
1

you can save the feeds as static files on the device or you can save them to the sqlitedb on the device or you can save them using core data. There are plenty of options with varying levels of difficulty.

Simple File read/write code

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

// the path to write file
NSString *appFile = [docPath stringByAppendingPathComponent:@"rssfile.xml"];

// write file to local directory
[rssData writeToFile:appFile atomically:NO]

// read file from local directory
NSData *rssData = [NSData dataWithContentsOfFile:appFile];
if (myData) {
    // do something
}
Aaron Saunders
  • 33,180
  • 5
  • 60
  • 80