【问题标题】:UIWebView force reload same URLUIWebView 强制重新加载相同的 URL
【发布时间】:2015-01-28 04:12:39
【问题描述】:

我有一个 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];
    }

有什么帮助吗?

【问题讨论】:

  • 我也有同样的问题...如果有人指导就好了..

标签: ios uiwebview reload nsurlcache


【解决方案1】:

试试这个代码示例..因为你必须清除 cookie 和缓存才能摆脱你的问题..这对我有用..

 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()

【讨论】:

    猜你喜欢
    • 2012-06-13
    • 1970-01-01
    • 1970-01-01
    • 2014-09-18
    • 1970-01-01
    • 1970-01-01
    • 2013-11-23
    • 2011-07-12
    相关资源
    最近更新 更多