I am trying to load UIWebView Offline with data from NSURLCache.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // setup cache int cacheSizeMemory = 4*1024*1024; // 4MB int cacheSizeDisk = 32*1024*1024; // 32MB NSURLCache *urlCache = [[NSURLCache alloc] initWithMemoryCapacity:cacheSizeMemory diskCapacity:cacheSizeDisk diskPath:@"nsurlcache"]; [NSURLCache setSharedURLCache:urlCache]; } -(void)loadWebView{ request = [NSURLRequest requestWithURL:myURL cachePolicy: NSURLRequestReturnCacheDataElseLoad timeoutInterval:1000]; [self.webView loadRequest:request]; }
When I try to load UIWebView offline it calls didFailWithError instead of connectionDidFinishLoading. My Cache directory however contains offline data and resources like css, js files but UIWebView is not able to access it.
I have confirmed this by overriding the following method:
-(NSCachedURLResponse *)cachedResponseForRequest:(NSURLRequest *)request { NSCachedURLResponse *response = [super cachedResponseForRequest:request]; if([response.data length]> 0){ // this is called for all css , js script files NSLog(@"Returning data from cache"); } return response; }
Moreover, the data is being returned from cache UIWebview fails to load it.