Reputation: 3780
I am receiving shouldstartloadwithrequest event and I need to stop request for some conditions. How to stop uiwebview request when shouldstartloadwithrequest? Thank you
Upvotes: 0
Views: 3996
Reputation: 56809
Check for the condition, then return NO
in shouldStartLoadWithRequest
. Make sure to set delegate appropriately and include the UIWebViewDelegate protocol in the interface of the delegate class.
Upvotes: 3
Reputation: 5314
You can invoke the stopLoading
method for the UIWebView
. Below code will check if the webview is loading and stop it.
if([webView isLoading]) {
[webView stopLoading];
}
EDIT: After re-reading your question, I understood you want to return NO
in the request to stop it from beginning to load, so you would do something like:
-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
//Check your condition:
if(myCondition == TRUE)
return NO;
return YES;
}
Upvotes: 3