处理涉及UIWebView
. 基本问题:- Ui Webview的行为与safari完全一样吗?
我们最后的场景是使用 ui webview 显示网络应用程序。可以使某些页面在离线模式下工作。如用户上网->浏览网页。现在没有连接,safari 仍然可以从缓存中加载网页根据为该页面所做的设置。(清单文件)。
但是,这种情况在我正在使用的应用程序中不起作用UIWebView
。我正在使用 ASIHttp 请求绕过代理并提供凭据。
如何使用UIWebView
.Caching 技术处理这种离线场景?请提供代码示例,因为我发现很难找到一些代码示例。
使用的代码如下:-
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];
}
使用缓存中的数据时,图像不显示。