Просмотр исходного кода

Make all GIDSignInCallback params nullable.

Peter Andrews 4 лет назад
Родитель
Сommit
51ccc95b78

+ 19 - 9
GoogleSignIn/Sources/GIDSignIn.m

@@ -185,14 +185,14 @@ static const NSTimeInterval kMinimumRestoredAccessTokenTimeToExpire = 600.0;
                                       profileData:nil];
 }
 
-- (void)restorePreviousSignInWithCallback:(GIDSignInCallback)callback {
+- (void)restorePreviousSignInWithCallback:(nullable GIDSignInCallback)callback {
   [self signInWithOptions:[GIDSignInInternalOptions silentOptionsWithCallback:callback]];
 }
 
 - (void)signInWithConfiguration:(GIDConfiguration *)configuration
        presentingViewController:(UIViewController *)presentingViewController
                            hint:(nullable NSString *)hint
-                       callback:(GIDSignInCallback)callback {
+                       callback:(nullable GIDSignInCallback)callback {
   GIDSignInInternalOptions *options =
       [GIDSignInInternalOptions defaultOptionsWithConfiguration:configuration
                                        presentingViewController:presentingViewController
@@ -203,7 +203,7 @@ static const NSTimeInterval kMinimumRestoredAccessTokenTimeToExpire = 600.0;
 
 - (void)signInWithConfiguration:(GIDConfiguration *)configuration
        presentingViewController:(UIViewController *)presentingViewController
-                       callback:(GIDSignInCallback)callback {
+                       callback:(nullable GIDSignInCallback)callback {
   [self signInWithConfiguration:configuration
        presentingViewController:presentingViewController
                            hint:nil
@@ -213,14 +213,16 @@ static const NSTimeInterval kMinimumRestoredAccessTokenTimeToExpire = 600.0;
 
 - (void)addScopes:(NSArray<NSString *> *)scopes
     presentingViewController:(UIViewController *)presentingViewController
-                    callback:(GIDSignInCallback)callback {
+                    callback:(nullable GIDSignInCallback)callback {
   // A currentUser must be available in order to complete this flow.
   if (!self.currentUser) {
     // No currentUser is set, notify callback of failure.
     NSError *error = [NSError errorWithDomain:kGIDSignInErrorDomain
                                          code:kGIDSignInErrorCodeNoCurrentUser
                                      userInfo:nil];
-    callback(nil, error);
+    if (callback) {
+      callback(nil, error);
+    }
     return;
   }
 
@@ -245,7 +247,9 @@ static const NSTimeInterval kMinimumRestoredAccessTokenTimeToExpire = 600.0;
     NSError *error = [NSError errorWithDomain:kGIDSignInErrorDomain
                                          code:kGIDSignInErrorCodeScopesAlreadyGranted
                                      userInfo:nil];
-    callback(nil, error);
+    if (callback) {
+      callback(nil, error);
+    }
     return;
   }
 
@@ -386,7 +390,9 @@ static const NSTimeInterval kMinimumRestoredAccessTokenTimeToExpire = 600.0;
       if (error) {
         [self authenticateWithOptions:options];
       } else {
-        options.callback(_currentUser, nil);
+        if (options.callback) {
+          options.callback(_currentUser, nil);
+        }
       }
     }];
   } else {
@@ -496,7 +502,9 @@ static const NSTimeInterval kMinimumRestoredAccessTokenTimeToExpire = 600.0;
     NSError *error = [NSError errorWithDomain:kGIDSignInErrorDomain
                                          code:kGIDSignInErrorCodeHasNoAuthInKeychain
                                      userInfo:nil];
-    options.callback(nil, error);
+    if (options.callback) {
+      options.callback(nil, error);
+    }
     return;
   }
 
@@ -659,7 +667,9 @@ static const NSTimeInterval kMinimumRestoredAccessTokenTimeToExpire = 600.0;
   __weak GIDAuthFlow *weakAuthFlow = authFlow;
   [authFlow addCallback:^() {
     GIDAuthFlow *handlerAuthFlow = weakAuthFlow;
-    _currentOptions.callback(_currentUser, handlerAuthFlow.error);
+    if (_currentOptions.callback) {
+      _currentOptions.callback(_currentUser, handlerAuthFlow.error);
+    }
   }];
 }
 

+ 4 - 4
GoogleSignIn/Sources/Public/GoogleSignIn/GIDSignIn.h

@@ -84,7 +84,7 @@ typedef void (^GIDDisconnectCallback)(NSError *_Nullable error);
 /// Attempts to restore a previously authenticated user without interaction.
 ///
 /// @param callback The `GIDSignInCallback` block that is called on completion.
-- (void)restorePreviousSignInWithCallback:(GIDSignInCallback)callback;
+- (void)restorePreviousSignInWithCallback:(nullable GIDSignInCallback)callback;
 
 /// Starts an interactive sign-in flow using the provided configuration.
 ///
@@ -99,7 +99,7 @@ typedef void (^GIDDisconnectCallback)(NSError *_Nullable error);
 /// @param callback The `GIDSignInCallback` block that is called on completion.
 - (void)signInWithConfiguration:(GIDConfiguration *)configuration
        presentingViewController:(UIViewController *)presentingViewController
-                       callback:(GIDSignInCallback)callback;
+                       callback:(nullable GIDSignInCallback)callback;
 
 /// Starts an interactive sign-in flow using the provided configuration and a login hint.
 ///
@@ -117,7 +117,7 @@ typedef void (^GIDDisconnectCallback)(NSError *_Nullable error);
 - (void)signInWithConfiguration:(GIDConfiguration *)configuration
        presentingViewController:(UIViewController *)presentingViewController
                            hint:(nullable NSString *)hint
-                       callback:(GIDSignInCallback)callback;
+                       callback:(nullable GIDSignInCallback)callback;
 
 /// Starts an interactive consent flow to add scopes to the current user's grants.
 ///
@@ -127,7 +127,7 @@ typedef void (^GIDDisconnectCallback)(NSError *_Nullable error);
 /// @param callback The `GIDSignInCallback` block that is called on completion.
 - (void)addScopes:(NSArray<NSString *> *)scopes
     presentingViewController:(UIViewController *)presentingViewController
-                    callback:(GIDSignInCallback)callback;
+                    callback:(nullable GIDSignInCallback)callback;
 
 /// Marks current user as being in the signed out state.
 - (void)signOut;