ios - Webview 不刷新图像

标签 ios swift

我正在使用加载 html 字符串方法将 Html 文件加载到 webview。一切正常。在我的代码中,用户选择图像作为配置文件并选择图像保存在修复路径和名称上。当用户选择图像时,当 web View 重新加载时,图像显示旧图像。图像更新到目录但不显示。 此问题仅在 Ipad 中出现,在 Iphone 中正常。

有什么建议。?那么请推荐

//我的加载代码

 webview.loadHTMLString(invoiceHTML, baseURL: NSURL(string:resumeComposer.HTMLFilePath)! as URL)

//Image Source更新为HTML String代码

imgPath = URL(fileURLWithPath: folderpathforNormal).appendingPathComponent("ProfileImg.png").path
HTMLContent = HTMLContent?.replacingOccurrences(of: "*userimage*", with: imgPath)

最佳答案

首先像这样清除 UIWebview 缓存:

//to remove cache from UIWebview
URLCache.shared.removeAllCachedResponses()
    if let cookies = HTTPCookieStorage.shared.cookies {
        for cookie in cookies {
            HTTPCookieStorage.shared.deleteCookie(cookie)
        }
    }

关于ios - Webview 不刷新图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45615412/

相关文章:

ios - 离开屏幕时,Tableview 部分标题无法正确转换

swift - 需要帮助调试我的 SpriteKit 应用程序中的崩溃

ios - 模糊效果 - 背景 UITextField

ios - Swift 可选链在闭包中不起作用

ios - 动态 tableViewCell 高度

ios - NSUser Defaults - 将 3 个变量保存在一起然后获取

ios - Xcode 在 BuildPhases 中尝试运行脚本时抛出 "No such file or directory"错误

ios - 在 Parse Analytics 中记录自定义事件是否需要 24 小时

ios - 如何将结构发送到 BLE writevalue 中?

ios - 在 Swift 3.0 中使用 SwiftyJSONModel 接收空值