简体   繁体   中英

Linkedin - iOS - Detect user cancel login

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?

Cancle视图错误

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM