我正在obj-c中编写一个iOS应用,并使用Google SignIn SDK来执行Google SignIn流程。我想要能够自定义按钮并对其进行一些操作,因此我继续GIDSignInDelegate
根据他们的文档来实现自己的协议。但是它会无缘无故地抛出异常。
这是我的视图控制器的最少代码。 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
我确实具有自定义登录流程google doc所需的任何委托方法。我错过了什么吗?
这是Google登录的基本解决方法...因此,请检查您缺少的内容
首先在您的按钮动作中使用
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
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句