From 5c1d50830cb0bf490826179c72b3200500c594c7 Mon Sep 17 00:00:00 2001 From: Vojtech Novak Date: Thu, 19 Sep 2024 22:23:34 +0200 Subject: [PATCH] feat: make sign in crash error more helpful --- ios/RNGoogleSignin.mm | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/ios/RNGoogleSignin.mm b/ios/RNGoogleSignin.mm index ebe5c2e1..530f9595 100644 --- a/ios/RNGoogleSignin.mm +++ b/ios/RNGoogleSignin.mm @@ -124,13 +124,22 @@ + (BOOL)requiresMainQueueSetup reject:(RCTPromiseRejectBlock)reject) { dispatch_async(dispatch_get_main_queue(), ^{ - UIViewController* presentingViewController = RCTPresentedViewController(); NSString* hint = options[@"loginHint"]; NSArray* scopes = self.scopes; - [GIDSignIn.sharedInstance signInWithPresentingViewController:presentingViewController hint:hint additionalScopes:scopes completion:^(GIDSignInResult * _Nullable signInResult, NSError * _Nullable error) { - [self handleCompletion:signInResult withError:error withResolver:resolve withRejector:reject fromCallsite:@"signIn"]; +#if DEBUG + @try { +#endif + [GIDSignIn.sharedInstance signInWithPresentingViewController:RCTPresentedViewController() hint:hint additionalScopes:scopes completion:^(GIDSignInResult * _Nullable signInResult, NSError * _Nullable error) { + [self handleCompletion:signInResult withError:error withResolver:resolve withRejector:reject fromCallsite:@"signIn"]; }]; +#if DEBUG + } + @catch (NSException *exception) { + NSString *errorMessage = [NSString stringWithFormat:@"Encountered an error when signing in (see more below). If the error is 'Your app is missing support for the following URL schemes...', follow the troubleshooting guide at https://react-native-google-signin.github.io/docs/troubleshooting#ios\n\n%@", exception.description]; + reject(@"SIGN_IN_ERROR", errorMessage, nil); + } +#endif }); }