自定义Google登录GIDSignInDelegate协议的抛出异常 [英] Custom Google Sign In throw exception on GIDSignInDelegate protocol

查看:1113
本文介绍了自定义Google登录GIDSignInDelegate协议的抛出异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在obj-c中编写一个iOS应用程序,并使用Google SignIn SDK来执行Google SignIn流程。我想能够自定义按钮和动作一点,所以我继续实施根据他们的文档自己的 GIDSignInDelegate 的协议。但是它没有理由抛出异常。



这是我的视图控制器的最小代码。
viewcontroller.m

  #importViewController.h 
#import< FBSDKLoginKit / FBSDKLoginKit.h>

@interface ViewController()


@property(weak,nonatomic)IBOutlet UIButton * GoogleSignIn;

@end

@implementation ViewController

- (void)viewDidLoad {
[super viewDidLoad];
//加载视图后,通常从笔尖进行任何其他设置。
}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
//处理可以重新创建的任何资源。
}


- (IBAction)googleButtonTouchUpInside:(id)sender {
[[GIDSignIn sharedInstance] signIn];
}

//仅当GIDSignInUIDelegate不是
// UIViewController的子类时才执行这些方法。

//停止用户
//按下登录按钮
- (void)signInWillDispatch:(GIDSignIn *)signIn error:(NSError)时启动的UIActivityIndi​​catorView动画*)error {
// [UIActivityIndi​​catorView stopAnimating];
}

//呈现提示用户使用Google
登录的视图 - (void)signIn:(GIDSignIn *)signIn
presentViewController:(UIViewController *)viewController {
[self presentViewController:viewController animated:YES completion:nil];
}

//关闭使用Google登录视图
- (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 signIn的基本工作环境...所以检查你的错误



首先在按钮操作中使用

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

然后为代表们

   - (void)signIn:(GIDSignIn *)signIn didSignInForUser:(GIDGoogleUser *)用户withError:(NSError *)错误{
//对此登录的用户执行任何操作。
if(error == nil){
NSString * userId = user.userID;
} else {
NSLog(@%@,error.localizedDescription);
}
}

- (void)signIn :( GIDSignIn *)signIn didDisconnectWithUser:(GIDGoogleUser *)用户withError:(NSError *)错误{
//用户在这里断开应用程序时执行任何操作。
}

- (void)signInWillDispatch:(GIDSignIn *)signIn错误:(NSError *)错误{
NSLog(@%@,error.description);
}

//呈现提示用户使用Google登录的视图
- (void)signIn:(GIDSignIn *)signIn presentViewController:(UIViewController *)viewController {
//当前视图控制器
}

//关闭使用Google登录视图
- (void)signIn:(GIDSignIn *)signIn dismissViewController: (UIViewController *)viewController {
//关闭视图控制器
}


I'm writing an iOS app in obj-c and using Google SignIn SDK to do the Google SignIn flow. I wanna be able to customize the button and action a little it so I went ahead implementing the protocols of GIDSignInDelegate myself based on their documentation. But it throws and exception for no reason.

Here's the minimal code of my 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

I do have whatever delegate method is required for a custom login flow google doc Did I miss anything?

解决方案

This is basic workaroung for google signIn ... so check what is missing for you

First of all in your button action use

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

Then for Delegates

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

这篇关于自定义Google登录GIDSignInDelegate协议的抛出异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆