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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With