gpt4 book ai didi

ios - 自定义 Google 登录在 GIDSignInDelegate 协议(protocol)上抛出异常

转载 作者:可可西里 更新时间:2023-11-01 05:01:03 25 4
gpt4 key购买 nike

我正在使用 obj-c 编写 iOS 应用程序并使用 Google SignIn SDK 执行 Google SignIn 流程。我希望能够自定义按钮并对其进行一些操作,因此我继续根据他们的文档自行实现 GIDSignInDelegate 的协议(protocol)。但它无缘无故抛出异常。

这是我的 View Controller 的最少代码。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

我确实拥有自定义登录流程所需的任何委托(delegate)方法 google doc我错过了什么吗?

最佳答案

这是谷歌登录的基本解决方法...所以请检查您缺少什么

首先在你的按钮操作中使用

GIDSignIn *signin = [GIDSignIn sharedInstance];
signin.shouldFetchBasicProfile = true;
signin.delegate = self;
signin.uiDelegate = self;
[signin signIn];

然后委托(delegate)

- (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
}

关于ios - 自定义 Google 登录在 GIDSignInDelegate 协议(protocol)上抛出异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38539531/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com