Due to an issue where I can’t get the NSURLRequest timeout to fire in my UIWebView, I am trying to use an NSTimer to check to see if I’ve got a response within a designated period. If I haven’t, then I want to cancel the request and warn the user.
However: I’m unable to find a way to cancel a current request that has been made in a UIWebView.
How do you do it?
I have setup the request for the UIWebView as follows:
NSString *theURL = [NSString stringWithFormat:@"https://%@%@", _hostname, LOGIN_PART_URL];
NSString *body = [NSString stringWithFormat:@"Username=%@&Password=%@", _username, _password];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc]initWithURL:[NSURL URLWithString:theURL]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:_timeoutInSecs];
[request setHTTPMethod: @"POST"];
[request setHTTPBody: [body dataUsingEncoding: NSUTF8StringEncoding]];
[web loadRequest:request];
I can see that NSURLConnection has a cancel method, but there seems to be no equivalent for UIWebView.
What am I missing?
Thanks!
Stretch 🙂
There is a
stopLoadingmethod inUIWebViewclass. Does it meet your needs?Per
UIWebViewClass Reference: