0

I want to copy cache data into database(sqlite/coreData) so that I can view while offline (without Internet) like " Reading List in Safari ". I read the code at Xcode UIWEBVIEW download , save HTML file and show which is following:-

- (void)viewDidLoad
{

    NSURL *url = [NSURL URLWithString:@"http://livedemo00.template-help.com/wt_37587/index.html"]; 


    //[WEBVIEW loadRequest:reqURL];


    // Determile cache file path
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *filePath = [NSString stringWithFormat:@"%@/%@", [paths objectAtIndex:0],@"index.html"];   

    // Download and write to file

    NSData *urlData = [NSData dataWithContentsOfURL:url];
    [urlData writeToFile:filePath atomically:YES];

    // Load file in UIWebView
    [WEBVIEW loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:filePath]]];      



    [super viewDidLoad];
}

But the problem with this code is that it does not show up images while offline .

So I thought that saving Data from Cache to database could be another option.Can anyone share some sample code to copy the website content along with images to database.

Thank You in advance

Community
  • 1
  • 1
Pawandeep Singh
  • 830
  • 1
  • 13
  • 25
  • possible duplicate of [Is it possible to cache resources loaded in an iPhone UIWebView?](http://stackoverflow.com/questions/345432/is-it-possible-to-cache-resources-loaded-in-an-iphone-uiwebview) – Vizllx Jun 01 '15 at 07:41

1 Answers1

0

You may used ASIWebPageRequest , example given here

Or

If reachability got connectivity

NSCachedURLResponse* response = [[NSURLCache sharedURLCache] 
                                     cachedResponseForRequest:[webView request]];
NSData* data = [response data];

Store data in locally and use it whenever you got reachability offline.

Community
  • 1
  • 1
Santu C
  • 2,644
  • 2
  • 12
  • 20