自定义Google Sign In在GIDSignInDelegate协议上抛出exception
我正在用obj-c编写一个iOS应用程序,并使用Google SignIn SDK来执行Google SignInstream程。 我想能够自定义button和动作一点,所以我继续执行GIDSignInDelegate
自己的协议基于他们的文档。 但它没有理由抛出和exception。
这是我的视图控制器的最小代码。 viewcontroller.m
#import "ViewController.h" #import <FBSDKLoginKit/FBSDKLoginKit.h> @interface ViewController () @property (weak, nonatomic) IBOutlet UIButton *GoogleSignIn; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (IBAction)googleButtonTouchUpInside:(id)sender { [[GIDSignIn sharedInstance] signIn]; } // Implement these methods only if the GIDSignInUIDelegate is not a subclass of // UIViewController. // Stop the UIActivityIndicatorView animation that was started when the user // pressed the Sign In button - (void)signInWillDispatch:(GIDSignIn *)signIn error:(NSError *)error { //[UIActivityIndicatorView stopAnimating]; } // Present a view that prompts the user to sign in with Google - (void)signIn:(GIDSignIn *)signIn presentViewController:(UIViewController *)viewController { [self presentViewController:viewController animated:YES completion:nil]; } // Dismiss the "Sign in with Google" view - (void)signIn:(GIDSignIn *)signIn dismissViewController:(UIViewController *)viewController { [self dismissViewControllerAnimated:YES completion:nil]; } @end
viewcontroller.h
#import <UIKit/UIKit.h> #import <Google/SignIn.h> @interface ViewController : UIViewController <GIDSignInUIDelegate> @end
我有任何代理方法是必需的自定义loginstream谷歌文档我错过了什么?
这是谷歌login的基本工作…所以检查什么是你失踪
首先在你的button动作中使用
GIDSignIn *signin = [GIDSignIn sharedInstance]; signin.shouldFetchBasicProfile = true; signin.delegate = self; signin.uiDelegate = self; [signin signIn];
然后代表
- (void)signIn:(GIDSignIn *)signIn didSignInForUser:(GIDGoogleUser *)user withError:(NSError *)error { // Perform any operations on signed in user here. if (error == nil) { NSString *userId = user.userID; } else { NSLog(@"%@", error.localizedDescription); } } - (void)signIn:(GIDSignIn *)signIn didDisconnectWithUser:(GIDGoogleUser *)user withError:(NSError *)error { // Perform any operations when the user disconnects from app here. } - (void)signInWillDispatch:(GIDSignIn *)signIn error:(NSError *)error { NSLog(@"%@",error.description); } // Present a view that prompts the user to sign in with Google - (void)signIn:(GIDSignIn *)signIn presentViewController:(UIViewController *)viewController { //present view controller } // Dismiss the "Sign in with Google" view - (void)signIn:(GIDSignIn *)signIn dismissViewController:(UIViewController *)viewController { //dismiss view controller }
更新了Swift 3:
在signIn中使用下面的代码行button操作方法 :
GIDSignIn.sharedInstance().uiDelegate = self GIDSignIn.sharedInstance().delegate = self GIDSignIn.sharedInstance().signIn()
注意:如果您在ViewController中的任何位置使用它,请在代码上面注释…! 否则会没事的。