を含むアプリケーションでの作業UIWebView
。基本的な質問:-Ui Webviewはサファリとまったく同じように動作しますか?
最後のシナリオは、ui webviewを使用してWebアプリを表示することです。一部のページはオフラインモードで動作させることができます。のように、ユーザーはオンラインになります-> Webページを閲覧します。これで接続がなくなり、safariはキャッシュからWebページをロードできます。そのページに対して行われた設定に従って。(マニフェストファイル)。
ただし、このシナリオは、を使用している私のアプリケーションでは機能しませんUIWebView
。ASIHttpリクエストを使用して、プロキシをバイパスし、資格情報を提供しています。
このオフラインシナリオは、使用するUIWebView
キャッシュ手法を使用してどのように処理できますか?コードサンプルを提供してください。これでいくつかのコードサンプルを見つけるのが難しいと感じています。
使用されるコードは次のとおりです:-
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];
}
キャッシュからのデータを使用すると、画像が表示されません。