views:

53

answers:

1

Now I try to build iPhone application, like magazine online, that can download new magazine form web and store in app (can play offline).

I no idea for implement feature download new magazine form online source and store in the app.

Please help me.

+1  A: 

Here's an example how you can download a file to your iPhone and reuse it later (in this case it's stores an HTML document that is then loaded to UIWebView from local store).

// downloading file
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
    NSUserDomainMask, YES);
NSString *dataPath = [paths objectAtIndex:0];
NSString *fileName = [[url path] lastPathComponent];
NSString *filePath = [dataPath stringByAppendingPathComponent:fileName];

if ([[NSFileManager defaultManager] fileExistsAtPath:filePath] == NO) {
    NSString *fileString = [NSString stringWithContentsOfURL:url 
                           encoding:NSUTF8StringEncoding 
                           error:nil];
    [fileString writeToFile:filePath 
                atomically:YES 
                encoding:NSUTF8StringEncoding 
                error:nil];
}

// use local file
NSURL *loadUrl = [[NSURL alloc] initFileURLWithPath: filePath];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL: loadUrl];
[webView loadRequest: request];
[request release];
[loadUrl release];
RaYell