The joys of didFailLoadWithError UIWebview

限于喜欢 提交于 2019-11-30 13:21:34

问题


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?


回答1:


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.




回答2:


from wiki

102 Processing (WebDAV; RFC 2518) As a WebDAV request may contain many sub-requests involving file operations, it may take a long time to complete the request. This code indicates that the server has received and is processing the request, but no response is available yet.[3] This prevents the client from timing out and assuming the request was lost.

from

WebKitErrorDomain A string used by NSError to indicate that the error was originated by a WebKit class.

looks loke web kit errors are something internal and author do not want to handle this error

UPDATE

do not see that there's && in condition. So that mean that if WebKitErrorDomain appears and code is 102 -- that means that web kit can not show page for now, because there're too many sub-requests and you have to wait a bit



来源:https://stackoverflow.com/questions/19959307/the-joys-of-didfailloadwitherror-uiwebview

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!