How to prevent the extra view displaying an access code when using Google OAuth 2.0

前端 未结 8 985
挽巷
挽巷 2020-12-14 12:18

I followed http://googlemac.blogspot.com/2011/05/ios-and-mac-sign-in-controllers.html to allow users to use Google to login to an iPhone app. After I tap \"Allow access\" bu

8条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-14 12:51

    I tried this trick and it gets work...

    replace the webview shouldStartLoadWithRequest with this below method in GTMOAuth2ViewControllerTouch.h. It will not show the authentication code page.

    *- (BOOL)webView:(UIWebView *)webView
      shouldStartLoadWithRequest:(NSURLRequest *)request
                  navigationType:(UIWebViewNavigationType)navigationType {
        if (!hasDoneFinalRedirect_)
        {
            hasDoneFinalRedirect_ = [signIn_ requestRedirectedToRequest:request];
    
            if ([request.URL.absoluteString rangeOfString:@"https://accounts.google.com/o/oauth2/approval?"].location != NSNotFound)
            {
                self.redirectView.frame=[UIScreen mainScreen].bounds;
                //webView.frame=[UIScreen mainScreen].bounds;
                [self.activityView startAnimating];
                [webView addSubview:self.redirectView];
    
                return YES;
            }
            else if(hasDoneFinalRedirect_) {
                // signIn has told the view to close
                return NO;
            }
        }
    
        return YES;
    }*
    

    in this I am adding my own custom view (redirectView) to this authentication page by checking this approval url https://accounts.google.com/o/oauth2/approval?

    and You should also add activityView in xib of GTMOAuth2ViewControllerTouch to show the loader while redirecting back to the application.

提交回复
热议问题