UIWebView强制重新加载相同的URL

时间:2014-11-29 20:16:53

标签: ios uiwebview reload nsurlcache

我有一个UIWebView,可以从像

这样的请求中加载页面
  NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:addressUrl cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:30];

[self.webView loadRequest:req];

然后我必须重新加载页面,但它重新加载相同的页面,它并没有真正重新加载页面。它使用某种缓存。

我还在重新加载URL之前清理所有缓存

    [[NSURLCache sharedURLCache] setDiskCapacity:0];
    [[NSURLCache sharedURLCache] setMemoryCapacity:0];
    [[NSURLCache sharedURLCache] removeAllCachedResponses];

 NSHTTPCookieStorage *cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
    NSArray *cookies = [cookieStorage cookies];
    for (NSHTTPCookie *cookie in cookies) {
        [cookieStorage deleteCookie:cookie];
    }

任何帮助?

1 个答案:

答案 0 :(得分:0)

尝试此代码示例....因为您必须清除Cookie和&amp ;;缓存以摆脱你的问题。这对我有用..

 NSURLCache.sharedURLCache().removeAllCachedResponses()

        var cookie : NSHTTPCookie = NSHTTPCookie()
        var cookieJar : NSHTTPCookieStorage = NSHTTPCookieStorage.sharedHTTPCookieStorage()
        for cookie in cookieJar.cookies as! [NSHTTPCookie]{
            NSLog("%@", cookie)
        }

        var storage : NSHTTPCookieStorage = NSHTTPCookieStorage.sharedHTTPCookieStorage()
        for cookie in storage.cookies  as! [NSHTTPCookie]{
            storage.deleteCookie(cookie)
        }
        NSUserDefaults.standardUserDefaults()