Linkedin - iOS - 检测用户取消登录 [英] Linkedin - iOS - Detect user cancel login

查看:260
本文介绍了Linkedin - iOS - 检测用户取消登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 OAuthStarterKit 中链接了运行和工作(Web视图很慢!)基本视图附带了一些用于检测弹出webview何时关闭的基本代码(看下面的功能)。

I have the linked in OAuthStarterKit running and working (the web view is slow!) the basic view comes with some basic code for detecting when the popup webview is closed (see the following function).

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

The problem is, it can't detect when the user clicks the cancel button when they are presented with a Linkedin sign-in page. url: 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;
}


推荐答案

答案!



这是我最终在我的代码中使用的内容!希望它对某人有帮助!

Answer!

This is what I ended up using in my code! Hope it helps someone!

- (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];
    }
}

这篇关于Linkedin - iOS - 检测用户取消登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆