Ios 如何退出谷歌&x2B;在iPhone上

Ios 如何退出谷歌&x2B;在iPhone上,ios,objective-c,iphone,uiwebview,google-plus,Ios,Objective C,Iphone,Uiwebview,Google Plus,我正在编写一个应用程序,用户可以使用Google+登录。我跟随GOOGLE开发者控制台,成功登录并通过Access_令牌获得了用户配置文件信息。我想通过web视图登录,但如何在登录后注销 我的Webview方法 -(void)addWebView { NSString *url = [NSString stringWithFormat:@"https://accounts.google.com/o/oauth2/auth?response_type=code&client_id

我正在编写一个应用程序,用户可以使用Google+登录。我跟随GOOGLE开发者控制台,成功登录并通过Access_令牌获得了用户配置文件信息。我想通过web视图登录,但如何在登录后注销

我的Webview方法

-(void)addWebView
{

    NSString *url = [NSString stringWithFormat:@"https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=%@&redirect_uri=%@&scope=%@&data-requestvisibleactions=%@",client_id,callbakc,scope,visibleactions];

    self.webview = [[UIWebView alloc]init];
    self.webview.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
    self.webview.delegate = self;
    [self.view addSubview:self.webview];
    [self.webview  loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]];


}
- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {
    //    [indicator startAnimating];
    if ([[[request URL] host] isEqualToString:@"localhost"]) {

        // Extract oauth_verifier from URL query
        NSString* verifier = nil;
        NSArray* urlParams = [[[request URL] query] componentsSeparatedByString:@"&"];
        for (NSString* param in urlParams) {
            NSArray* keyValue = [param componentsSeparatedByString:@"="];
            NSString* key = [keyValue objectAtIndex:0];
            if ([key isEqualToString:@"code"]) {
                verifier = [keyValue objectAtIndex:1];
                NSLog(@"verifier %@",verifier);
                break;
            }
        }

        if (verifier) {
            NSString *data = [NSString stringWithFormat:@"code=%@&client_id=%@&client_secret=%@&redirect_uri=%@&grant_type=authorization_code", verifier,client_id,secret,callbakc];
            NSString *url = [NSString stringWithFormat:@"https://accounts.google.com/o/oauth2/token"];
            NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:url]];
            [request setHTTPMethod:@"POST"];
            [request setHTTPBody:[data dataUsingEncoding:NSUTF8StringEncoding]];
            NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:request delegate:self];
            receivedData = [[NSMutableData alloc] init];

        } else {
            // ERROR!
        }

        [webView removeFromSuperview];

        return NO;
    }
    return YES;
}

你不再需要自己做这件事了。从2.0.0开始,将允许您使用webview

- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  NSError* configureError;
  [[GGLContext sharedInstance] configureWithError: &configureError];
  NSAssert(!configureError, @"Error configuring Google services: %@", configureError);
  [GIDSignIn sharedInstance].allowsSignInWithWebView = YES;
  [GIDSignIn sharedInstance].allowsSignInWithBrowser = NO;
  [GIDSignIn sharedInstance].delegate = self;
  // ...
}
用户登录后,您将在didSignInForUser中收到所有相关详细信息:

- (void)signIn    :(GIDSignIn *)signIn
  didSignInForUser:(GIDGoogleUser *)user
         withError:(NSError *)error {
  // Perform any operations on signed in user here.
  NSString *userId = user.userID;                  // For client-side use only!
  NSString *idToken = user.authentication.idToken; // Safe to send to the server
  NSString *name = user.profile.name;
  NSString *email = user.profile.email;
}
稍后,当您要注销用户时,只需在sharedInstance单例上调用SignOut方法:

[GIDSignIn sharedInstance].signOut();
您应该尝试Google登录示例,以查看如何使用SDK的完整示例:

pod try Google

您好,您能给我发送这个库的示例代码吗示例代码是在您执行
pod try Google
时下载的,或者,您可以从这里开始:或者