Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The joys of didFailLoadWithError UIWebview

Tags:

ios

uiwebview

If you look at the code here:

https://github.com/evernote/evernote-sdk-ios/blob/master/evernote-sdk-ios/internal/ENOAuthViewController.m

that implement OAuth 2.0 flow in UIWebView.

The author uses this code for the didFailLoadWithError delegate function:

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
    if ([error.domain isEqualToString:@"WebKitErrorDomain"] && error.code == 102) {

        return;
    }

    if (error.code == NSURLErrorCancelled) {
        // ignore rapid repeated clicking (error code -999)
        return;
    }
}

Why is he ignoring those two errors (NSURLErrorCancelled) and error code 102?

like image 678
Kermit the Frog Avatar asked Nov 13 '13 16:11

Kermit the Frog


1 Answers

Error code 102 from the WebKitErrorDomain is the error that is raised by the UIWebView if its delegate returns FALSE from webView:shouldStartLoadWithRequest:navigationType. When implementing the OAuth2 flow with a UIWebView it is common to do this when the final redirection URL is encountered as this means it's time to hide the web view and start the process of exchanging the access code in the URL with an token directly from the authentication provider.

The second error is something I'm less familiar with but based on the code comment provided and the accepted answer to this question, I suspect there's some logic in the browser or UIWebView that automatically filters out fast repeated clicks. The error is probably being raised by design so that delegates can be notified of this if they're interested.

like image 56
steve84 Avatar answered Oct 10 '22 21:10

steve84