我在out中使用以下代码进行登录:
- (IBAction)signIn:(ID)sender { if(!isSignedIn){ [self signOutFromAll]; Nsstring *keychainItemname = nil; // save keychain keychainItemname = kKeychainItemname; Nsstring *scope = @"https://www.GoogleAPIs.com/auth/plus.me"; Nsstring *clIEntID = kClIEntID; Nsstring *clIEntSecret = kClIEntSecret; SEL finishedSel = @selector(vIEwController:finisheDWithAuth:error:); GTMOAuth2VIEwControllertouch *vIEwController; vIEwController = [GTMOAuth2VIEwControllertouch controllerWithScope:scope clIEntID:clIEntID clIEntSecret:clIEntSecret keychainItemname:keychainItemname delegate:self finishedSelector:finishedSel]; [[self navigationController]pushVIEwController:vIEwController animated:YES]; } else { [self displayAlertWithMessage:@"Currently Signed in."]; } }- (IBAction)signOut:(ID)sender { [self signOutFromAll]; [self displayAlertWithMessage:@"Signed out."]; }
这是代表:
- (voID)vIEwController:(GTMOAuth2VIEwControllertouch *)vIEwController finisheDWithAuth:(GTMOAuth2Authentication *)auth error:(NSError *)error{ if(error != nil){ // Authentication Failed... NSLog(@"Authentication error: %@",error); NSData *responseData = [[error userInfo] objectForKey:@"data"]; if([responseData length] > 0) NSLog(@"%@",[[[Nsstring alloc]initWithData:responseData enCoding:NSUTF8StringEnCoding]autorelease]); self.auth = nil; } else { // Authentication succeeded... isSignedIn = YES; self.auth = auth; }}
和awakeFromNib:
- (voID)awakeFromNib{ // Fill in the ClIEnt ID and ClIEnt Secret text fIElds NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; // First,we'll try to get the saved Google authentication,if any,from the keychain // normal applications will hardcode in their clIEnt ID and clIEnt secret,// But the sample app allows the user to enter them in a text fIEld,and saves them in the preferences Nsstring *clIEntID = [defaults stringForKey:kGoogleClIEntIDKey]; Nsstring *clIEntSecret = [defaults stringForKey:kGoogleClIEntSecretKey]; GTMOAuth2Authentication *auth; auth = [GTMOAuth2VIEwControllertouch authForGoogleFromKeychainForname:kKeychainItemname clIEntID:clIEntID clIEntSecret:clIEntSecret]; if (auth.canAuthorize) { // There is saved Google authentication // self.serviceSegments.selectedSegmentIndex = 0; } // Save the authentication object,which holds the auth tokens self.auth = auth; [self setAuth:auth]; isSignedIn = self.auth.canAuthorize;}
顺便说一句,我对这些代码的引用是在这个链接上:http://code.google.com/p/gtm-oauth2/wiki/Introduction#Using_the_OAuth_2_Controllers
解决方法 来自文档:The keychain item name is used to save the token on the user’s keychain,and should IDentify both your application name and the service name(s). If keychainItemname is nil,the token will not be saved,and the user will have to sign in again the next time the application is run.
http://code.google.com/p/gtm-oauth2/wiki/Introduction
因此,从您的代码中,它取决于kKeychainItemname的设置.
我以为在阅读文档时我会对此发表评论.
总结以上是内存溢出为你收集整理的iOS:Google身份验证代码全部内容,希望文章能够帮你解决iOS:Google身份验证代码所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)