Reputation: 63359
I have an app which uses UIWebview
heavily, most of my App are HTML files in a webserver. Something strange happened recently, after some time using, the UIWebview stop loading HTML from web(the webserver didn't receive any HTTP request by seeing the logs). The UIWebview
still can see the HTML, I doubt that the UIWebview
was loading HTML file from local cache
.
But after loading the HTML file, the UIWebview
didn't run any javascript in that HTML file, which will issue many AJAX request.
I need to manually uninstall the App and reinstall it to make it work again, kill the App and restart can't help.
I am wondering that this is related to UIWebview
cache, because each time it occurs, the App is used for some time (several weeks).
Does any one encounters the same problems before? How to resolve it?
It is randomly happening and hard to reproduce.
Upvotes: 0
Views: 635
Reputation: 706
Why don't you set cache policy for the request. I think that way you can choose when to load from cache and when to reload it. Something like the code below might help.
let url = NSURL (string: yourUrlString);
var cachePolicy: NSURLRequestCachePolicy?
//check if connected to network
if(conected to network){
cachePolicy = .ReloadIgnoringLocalCacheData
}
else{
cachePolicy = .ReturnCacheDataDontLoad
}
let request = NSURLRequest(URL: url!, cachePolicy: cachePolicy, timeoutInterval: 15.0)
yourwebView.loadRequest(request)
Upvotes: 1