Google 登录 SDK 2.0.1 iOS 错误

Google sign-in SDK 2.0.1 for iOS error

我正在尝试将 Google 登录集成到我正在使用 'Google sign-in SDK 2.0.1' 的项目中。 我已按照 developer.google 网站上显示的步骤进行操作,但是当我单击按钮时 returns 在 - (void)signIn:(GIDSignIn *)signIn didSignInForUser:(GIDGoogleUser *)user withError:(NSError *)error

中出现错误 'Unknown error'

我已经集成了 2 个 url 方案和 app-delegate,VC 实现,如教程

所示

这是 ViewController 的代码,我在其中实现了登录按钮

@interface ViewController () < GIDSignInUIDelegate,GIDSignInDelegate>
@property (weak, nonatomic) IBOutlet GIDSignInButton *btnSignin;

@end

@implementation ViewController

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [GIDSignIn sharedInstance].uiDelegate = self;
    [GIDSignIn sharedInstance].delegate = self;

}

// ---------------------------------------------------------------------

#pragma mark - GIDSignInDelegate

- (void)signIn:(GIDSignIn *)signIn
didSignInForUser:(GIDGoogleUser *)user
     withError:(NSError *)error {
    if (error) {
        NSLog(@"Error in signin %@",[error localizedDescription]);
        return;
    }
}

// ---------------------------------------------------------------------


- (void)signIn:(GIDSignIn *)signIn
didDisconnectWithUser:(GIDGoogleUser *)user
     withError:(NSError *)error {
    if (error) {
        NSLog(@"Error did disconnect %@",[error localizedDescription]);
        return;
    }
}

@end

具体的错误代码是什么?通常,您会看到随异常一起返回的消息:

2015-06-18 16:36:49.463 SignInExample[20038:2727845] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Your app must support the following URL schemes: (null)'

同时有几件事可以帮助诊断:

  • 您可能希望从 the Google Sign-in quickstart 开始 运行 pod try Google 并使用 [[GGLContext sharedInstance] configureWithError: &configureError]; 配置项目

  • 如果您不调用 configureWithError,您应该设置客户端 ID,通常在您的 AppDelegate 中完成,例如:

    [GIDSignIn sharedInstance].clientID = "YOUR_CLIENT_ID";

  • 查看 Web 浏览器地址(如果您在模拟器中进行测试)以确保客户端 ID 已传递到登录流程

  • 确保将反向客户端 ID 添加到您的 URL 方案中