Working on a application that involves UIWebView
.
Basic Question :- Does Ui Webview behave exactly as safari ?
Scenario at our end is displaying web apps using ui webview .Some Pages can be made to work in offline mode .As in , user goes online - > browses web page .Now there is no connection , safari can still load web page from its cache as per settings made for that page .( manifest file ) .
However this scenario does not work in my application which is using UIWebView
.
I am using ASIHttp request to bypass proxy and provide credentials .
How can this offline scenario be handled using UIWebView
.Caching techniques to be used ?
Please provide code sample , because i am finding it difficult to find some code samples on this .
The code used is as follows :-
ASIHTTPRequest *request1 = [ASIHTTPRequest requestWithURL:navigationURL];
[request1 setDownloadCache:[ASIDownloadCache sharedCache]];
[[ASIDownloadCache sharedCache] setShouldRespectCacheControlHeaders:NO];
[request1 setCachePolicy:ASIOnlyLoadIfNotCachedCachePolicy];
[request1 setCacheStoragePolicy:ASICachePermanentlyCacheStoragePolicy];
[request1 setDownloadDestinationPath:
[[ASIDownloadCache sharedCache] pathToStoreCachedResponseDataForRequest:request1]];
// ************ Network Status check
NetworkStatus status = [self.retrive1.internetreachbility currentReachabilityStatus];
if (status == ReachableViaWiFi || status == ReachableViaWWAN) {
[[ASIDownloadCache sharedCache] clearCachedResponsesForStoragePolicy:ASICachePermanentlyCacheStoragePolicy];
[request1 setShouldPresentProxyAuthenticationDialog:YES];
[request1 setShouldPresentCredentialsBeforeChallenge:YES];
[request1 setShouldPresentAuthenticationDialog:YES];
[request1 setUsername:retrive1.username];
[request1 setPassword:retrive1.password];
[request1 setDelegate:self];
[request1 setDidFinishSelector:@selector(webPageFetchSucceeded:)];
[request1 startAsynchronous];
}
else
{
NSLog(@"app is offline");
[request1 useDataFromCache];
BOOL success = [request1 didUseCachedResponse];
NSLog(@"------------>>>>>>> Success is %@\n", (success ? @"YES" : @"NO"));
off_status.text = [NSString stringWithFormat:@"Success is %@", (success ? @"YES" : @"NO")];
// Not using this method .
*NSData *responseData = [request1 responseData];
[web loadData:responseData MIMEType:@"text/html" textEncodingName:@"utf-8" baseURL:nil];*
// Using this method
NSString *response = [NSString stringWithContentsOfFile:
[request1 downloadDestinationPath] encoding:[request1 responseEncoding] error:nil];
[web loadHTMLString:response baseURL:nil];
}
Images are not getting displayed when using data from cache .