ios - 如何在 iPhone 上使用 Google+ 退出
<p><p>我正在编写一个用户可以使用 Google+ 登录的应用程序。我跟着GOOGLE开发者控制台成功登录,通过Access_Token获取用户文件信息。我想通过网页 View 登录,但是登录后如何注销?</p>
<p>我的 Webview 方法</p>
<pre><code>-(void)addWebView
{
NSString *url = ;
self.webview = [init];
self.webview.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
self.webview.delegate = self;
;
]];
}
- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {
// ;
if ([[ host] isEqualToString:@"localhost"]) {
// Extract oauth_verifier from URL query
NSString* verifier = nil;
NSArray* urlParams = [[ query] componentsSeparatedByString:@"&"];
for (NSString* param in urlParams) {
NSArray* keyValue = ;
NSString* key = ;
if () {
verifier = ;
NSLog(@"verifier %@",verifier);
break;
}
}
if (verifier) {
NSString *data = ;
NSString *url = ;
NSMutableURLRequest *request = [ initWithURL:];
;
];
NSURLConnection *theConnection=[ initWithRequest:request delegate:self];
receivedData = [ init];
} else {
// ERROR!
}
;
return NO;
}
return YES;
}
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>您不再需要自己执行此操作。从 2.0.0 开始,<a href="https://developers.google.com/identity/sign-in/ios/" rel="noreferrer noopener nofollow">Google Sign-in with the Identity SDK</a>将允许您使用 webview。</p>
<pre><code>- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
NSError* configureError;
[ configureWithError: &configureError];
NSAssert(!configureError, @"Error configuring Google services: %@", configureError);
.allowsSignInWithWebView = YES;
.allowsSignInWithBrowser = NO;
.delegate = self;
// ...
}
</code></pre>
<p>用户登录后,您将在 didSignInForUser 中收到所有相关详细信息:</p>
<pre><code>- (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;
}
</code></pre>
<p>稍后,当您想将用户注销时,只需在 sharedInstance 单例上调用 SignOut 方法即可:</p>
<pre><code>.signOut();
</code></pre>
<p>您应该试用 Google 登录示例以查看有关如何使用 SDK 的完整示例:</p>
<pre><code>pod try Google
</code></pre></p>
<p style="font-size: 20px;">关于ios - 如何在 iPhone 上使用 Google+ 退出,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/31801446/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/31801446/
</a>
</p>
页:
[1]