Reputation: 3759
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 :)
Upvotes: 3
Views: 6035
Reputation: 42163
There is a stopLoading
method in UIWebView
class. Does it meet your needs?
Per UIWebView
Class Reference:
stopLoading
Stops the loading of any web content managed by the receiver.
- (void)stopLoading
Stops any content in the process of being loaded by the main frame or any of its children frames. Does nothing if no content is being loaded.
Upvotes: 10