ios - 使用 cachePolicy 出错

标签 ios swift

因为我正在使用 cachePolicy在我的 UIWebView 中我得到这个错误:

0x196a994c8 <+28>: ldr x9, [x19] WebThread (6): EXC_BAD_ACCESS (code =1, address=0x8)

如果我先在代码中打开没有 cachePolicy 的 View ,然后编辑代码以具有 cachePolicy 并重新构建它,它确实有效。

但是,如果我在一部从未启动过该 View 的手机上直接使用 cachePolicy 启动该 View ,则它不起作用。

这是我的代码(给出错误):

var url = NSURL(string: "http://visia-ontwikkeling.nl/polen/pages.php?page=information_point")
let requestObj = NSURLRequest(URL: url!, cachePolicy: NSURLRequestCachePolicy.ReturnCacheDataDontLoad, timeoutInterval: 5);
webViewLabel.loadRequest(requestObj);

这就是它的工作原理,但没有缓存:

var url = NSURL(string: "http://visia-ontwikkeling.nl/polen/pages.php?page=information_point")
let requestObj = NSURLRequest(URL: url!);
webViewLabel.loadRequest(requestObj);

enter image description here

最佳答案

我建议你查看NSUrlCache .我认为您的缓存策略是错误的。您强制您的请求获取缓存数据,即使它不存在。你应该使用 NSURLRequestReturnCacheDataElseLoad。如:

var url = NSURL(string: "http://visia-ontwikkeling.nl/polen/pages.php?page=information_point")
let requestObj = NSURLRequest(URL: url!, cachePolicy: NSURLRequestCachePolicy. ReturnCacheDataElseLoad, timeoutInterval: 5)
webViewLabel.loadRequest(requestObj)

关于ios - 使用 cachePolicy 出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32606196/

相关文章:

ios - 检测何时触摸 Touch ID,无需身份验证

ios - 空数组错误 - 无法将数据从现有的 NSMutableArray 传递到 NSString

ios - MKAnnotation 未在 iOS5 中被选中

ios - 使用 UISearchController 搜索自定义对象

ios - 在 SwiftUI 中初始化 Slider 值

ios - Apple 拒绝第三方注册

ios - Swift - CoreData 故障

ios - View Controller 之间的共享 UI 功能

ios - 尝试转换为 NSFetchedResultsController "fatal error: unexpectedly found nil while unwrapping an Optional value"?

ios - UI测试: UINavigationBar popped from the stack still exists