Jaume
Jaume

Reputation: 3780

ios uiwebview stop request when shouldstartloadwithrequest

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

Answers (2)

nhahtdh
nhahtdh

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

skram
skram

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

Related Questions