在iOS 7中,我能夠將共享URL緩存設置為NSURLCache得子類,我創建得任何UIWebViews都會自動為每個請求使用該共享緩存.
// Set the URL cache and leave it set permanentlyExampleURLCache *cache = [[ExampleURLCache alloc] init];[NSURLCache setSharedURLCache:cache];
但是,現在在iOS 8中,似乎UIWebView從共享緩存中拉出來并且cachedResponseForRequest永遠不會被調用.
有沒有人找到這個變化得文檔,或者
解決方法
?解決方法
我今天遇到了同樣得問題.它在ios7上沒問題,在ios8上壞了.
訣竅是創建自己得緩存,這是你在didFinishLaunchingWithOptions中做得第一件事.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ // IMPORTANT: call this line before anything else. Do not call [NSURLCache sharedCache] before this because that // creates a reference and then we can't create the new cache. NSURLCache *URLCache = [[NSURLCache alloc] initWithMemoryCapacity:4 * 1024 * 1024 diskCapacity:20 * 1024 * 1024 diskPath:nil]; [NSURLCache setSharedURLCache:URLCache];...
您可以在其他應用中看到此操作:
https://github.com/AFNetworking/AFNetworking/blob/master/Example/AppDelegate.m
這個網站雖然陳舊,卻有更多信息說明為什么你甚至不應該在上面得代碼之前調用[NSURLCache sharedInstance]:
http://inessential.com/2007/02/28/figured_it_the_heck_out
以上是來客網為你收集整理得在iOS 8上共享NSURLCache和UIWebView全部內容,希望內容能夠幫你解決在iOS 8上共享NSURLCache和UIWebView所遇到得程序開發問題。
如果覺得來客網網站內容還不錯,歡迎將來客網網站推薦給程序員好友。
聲明:所有內容來自互聯網搜索結果,不保證100%準確性,僅供參考。如若本站內容侵犯了原著者的合法權益,可聯系我們進行處理。