开发者

Downloading plist (database) from internet?

I'm trying to download a database plist file from the internet. I later load the contents into a UITableView, but that isn't really the question (I figured it out already). What I have now is a list of football matches in my plist, with the results missing (as the matches were not played yet.) I successfully loaded that plist (it's in my project directory).

I use this path

[[NSBundle mainBundle] pathForResource:@"data" ofType:@"plist"]

My questions are

  1. How can I download the data
  2. How can I show a "activity indicator" while downloading?
  3. Where is the downloaded data saved? (so I use it as a path like the one above)
  4. How can I make the app use the older version, if the new one can't be downloaded (due to internet connection problems)

With my map I already provide an empty database (without the result), so if there is no internet connection during the first开发者_开发百科 launch (after the app is downloaded), this can be used.

Thanks a lot in advance!


Use NSURLConnection to download data, preferably in a separate thread.


I used ASIHTTPRequest classes, and it works pretty well... It downloads ALL filetypes, not only .plist ... you can really do many things with it (upload... etc) and the best part that it is both iPhone and Mac OS X compatible... The documentation is well made and the whole thing comes with a sample project :). So its easy to use.

Install everything like the website says, add the frameworks, import the "ASIHTTPRequest.h" in the class you want to download the files.

Play around with the code (I'm posting mine...), and viola, works nice and smooth...

// setting the save path... 
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *path = [paths objectAtIndex:0];
    NSString *downloadPath = [NSString stringWithFormat:@"%@/data.plist",path];
//creating download / upload request like...
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"http://martin.archplan.sk/data.plist"]];
    [request setDidFailSelector:@selector(downloadFailed)];
    [request setDidFinishSelector:@selector(parseData)];
    [request setTimeOutSeconds:5];
    [request setDelegate:self];
    [request setDownloadDestinationPath:downloadPath];
    [request startSynchronous];

Everyone who tried to help, thank you very much!!

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜