Ian*_*hao 4 delegates objective-c ios google-signin
我在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
Run Code Online (Sandbox Code Playgroud)
viewcontroller.h
#import <UIKit/UIKit.h>
#import <Google/SignIn.h>
@interface ViewController : UIViewController <GIDSignInUIDelegate>
@end
Run Code Online (Sandbox Code Playgroud)
我确实有自定义登录流程所需的任何委托方法google doc 我错过了什么吗?
EI *_*2.0 17
这是google signIn的基本工作方式...所以请检查一下你缺少什么
首先在你的按钮动作中使用
GIDSignIn *signin = [GIDSignIn sharedInstance];
signin.shouldFetchBasicProfile = true;
signin.delegate = self;
signin.uiDelegate = self;
[signin signIn];
Run Code Online (Sandbox Code Playgroud)
然后代表
- (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
}
Run Code Online (Sandbox Code Playgroud)
针对Swift 3进行了更新:
在signIn按钮操作方法中使用下面的代码行:
GIDSignIn.sharedInstance().uiDelegate = self
GIDSignIn.sharedInstance().delegate = self
GIDSignIn.sharedInstance().signIn()
Run Code Online (Sandbox Code Playgroud)
注意:如果您在ViewController中的任何位置使用它,请在上面的代码行注释...!否则会好的.
| 归档时间: |
|
| 查看次数: |
5797 次 |
| 最近记录: |