0

我有OAuthStarterKit运行和工作的链接(网络视图很慢!)基本视图带有一些基本代码,用于检测弹出式网络视图何时关闭(参见以下函数)。

问题是,当用户看到 Linkedin 登录页面时,它无法检测到用户何时单击取消按钮。网址:https://www.linkedin.com/uas/oauth/www.core.me

我将如何过滤“已取消”页面?

取消视图 错误

过滤/关闭代码

- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType 
{
    NSURL *url = request.URL;
    NSString *urlString = url.absoluteString;

    addressBar.text = urlString;
    [activityIndicator startAnimating];

    BOOL requestForCallbackURL = ([urlString rangeOfString:linkedInCallbackURL].location != NSNotFound);
    if ( requestForCallbackURL )
    {
        BOOL userAllowedAccess = ([urlString rangeOfString:@"user_refused"].location == NSNotFound);
        if ( userAllowedAccess )
        {            
            [self.requestToken setVerifierWithUrl:url];
            [self accessTokenFromProvider];
        }
        else
        {
            // User refused to allow our app access
            // Notify parent and close this view
            [[NSNotificationCenter defaultCenter] 
                    postNotificationName:@"loginViewDidFinish"        
                                  object:self 
                                userInfo:nil];

            [self dismissModalViewControllerAnimated:YES];
        }
    }
    else
    {
        // Case (a) or (b), so ignore it
    }
    return YES;
}
4

1 回答 1

0

回答!

这就是我最终在我的代码中使用的!希望它可以帮助某人!

- (void)webViewDidFinishLoad:(UIWebView *)mwebView
{
    [activityIndicator stopAnimating];
    NSString *html = [mwebView stringByEvaluatingJavaScriptFromString:
                      @"document.body.innerHTML"];

    if ([html rangeOfString:@"Page Not Found"].location != NSNotFound) {
        // This could be any string - I used "Page Not Found" 
        [[NSNotificationCenter defaultCenter]
         postNotificationName:@"loginViewDidFinish"
         object:self
         userInfo:nil];

        [self dismissModalViewControllerAnimated:YES];
    }
}
于 2012-08-24T08:50:53.373 回答