Linkedin - iOS - Detect user cancel login

只愿长相守 提交于 2019-12-23 04:40:08

问题


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).

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.

How would I go about filtering the 'canceled' page?

Filtering/closing code

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

回答1:


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


来源:https://stackoverflow.com/questions/12105908/linkedin-ios-detect-user-cancel-login

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