1
當我目前是新手到iOS開發試圖獲得高速緩存策略(NSURLRequestReturnCacheDataDontLoad)從緩存中拉來查看網頁,一邊在離線的iPhone正在使用的工作和(飛行模式)。我目前使用Apple提供的Reachability API來確定網絡/ wifi連接是否啓動並運行。這工作正常,但是當我去飛行模式,我沒有得到一個網頁來填充UIWebView。任何建議將非常有幫助,我環顧網上,但沒有找到很多有用的鏈接。謝謝。離線模式沒有使用NSURLRequestReturnCacheDataDontLoad
的代碼如下:
*- (IBAction)refresh:(id)sender
{
NSURL *url = [NSURL URLWithString:_entry.articleUrl];
NSURLRequest *webRequest = nil;
NSString *articleUrl = [_entry.articleUrl substringFromIndex:7];
NSArray *myArray = [articleUrl componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"/"]];
NSString *hostUrl = [myArray objectAtIndex:0];
NSLog(@"%@", hostUrl);
Reachability *reachability = [Reachability reachabilityWithHostName:hostUrl];
NetworkStatus netStatus = [reachability currentReachabilityStatus];
[[NSURLCache sharedURLCache] setMemoryCapacity:1024*1024*10];
// Verify current help file cache if we have network connection...
if (netStatus == ReachableViaWWAN || netStatus == ReachableViaWiFi)
{
webRequest = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:30];
}
else
{
// Network NOT reachable - show (local) cache if it exists
webRequest = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReturnCacheDataDontLoad timeoutInterval:30];
}
[_webView loadRequest:webRequest];
}*