From 9c9b36af86a4dd3da16048a36cf37351e63ccfe1 Mon Sep 17 00:00:00 2001 From: Peter Andrews Date: Tue, 13 Sep 2022 13:26:13 -0700 Subject: [PATCH] Revert "Revert "Temporarily revert breaking API changes for 6.2.3 patch release (#200)" (#201)" This reverts commit 8345fcc43c38cefb67f1ad0d5dcd51a1d036e460. --- GoogleSignIn/Sources/GIDAuthentication.m | 14 +-- GoogleSignIn/Sources/GIDSignIn.m | 82 +++++++------- .../Sources/GIDSignInInternalOptions.h | 14 +-- .../Sources/GIDSignInInternalOptions.m | 20 ++-- .../Public/GoogleSignIn/GIDAuthentication.h | 13 ++- .../Sources/Public/GoogleSignIn/GIDSignIn.h | 100 +++++++++--------- .../Tests/Unit/GIDSignInInternalOptionsTest.m | 13 ++- GoogleSignIn/Tests/Unit/GIDSignInTest.m | 90 ++++++++-------- .../ObjC/SignInSample/Source/AppDelegate.m | 4 +- .../Source/SignInViewController.m | 8 +- 10 files changed, 179 insertions(+), 179 deletions(-) diff --git a/GoogleSignIn/Sources/GIDAuthentication.m b/GoogleSignIn/Sources/GIDAuthentication.m index 7965db1e..dcf7cc2f 100644 --- a/GoogleSignIn/Sources/GIDAuthentication.m +++ b/GoogleSignIn/Sources/GIDAuthentication.m @@ -228,17 +228,17 @@ - (NSString *)emmSupport { return authorization; } -- (void)doWithFreshTokens:(GIDAuthenticationCompletion)completion { +- (void)doWithFreshTokens:(GIDAuthenticationAction)action { if (!([self.accessTokenExpirationDate timeIntervalSinceNow] < kMinimalTimeToExpire || (self.idToken && [self.idTokenExpirationDate timeIntervalSinceNow] < kMinimalTimeToExpire))) { dispatch_async(dispatch_get_main_queue(), ^{ - completion(self, nil); + action(self, nil); }); return; } @synchronized (_authenticationHandlerQueue) { // Push the handler into the callback queue. - [_authenticationHandlerQueue addObject:[completion copy]]; + [_authenticationHandlerQueue addObject:[action copy]]; if (_authenticationHandlerQueue.count > 1) { // This is not the first handler in the queue, no fetch is needed. return; @@ -286,9 +286,9 @@ - (void)doWithFreshTokens:(GIDAuthenticationCompletion)completion { authenticationHandlerQueue = [self->_authenticationHandlerQueue copy]; [self->_authenticationHandlerQueue removeAllObjects]; } - for (GIDAuthenticationCompletion completion in authenticationHandlerQueue) { + for (GIDAuthenticationAction action in authenticationHandlerQueue) { dispatch_async(dispatch_get_main_queue(), ^{ - completion(error ? nil : self, error); + action(error ? nil : self, error); }); } }]; @@ -298,9 +298,9 @@ - (void)doWithFreshTokens:(GIDAuthenticationCompletion)completion { authenticationHandlerQueue = [self->_authenticationHandlerQueue copy]; [self->_authenticationHandlerQueue removeAllObjects]; } - for (GIDAuthenticationCompletion completion in authenticationHandlerQueue) { + for (GIDAuthenticationAction action in authenticationHandlerQueue) { dispatch_async(dispatch_get_main_queue(), ^{ - completion(error ? nil : self, error); + action(error ? nil : self, error); }); } #endif // TARGET_OS_IOS && !TARGET_OS_MACCATALYST diff --git a/GoogleSignIn/Sources/GIDSignIn.m b/GoogleSignIn/Sources/GIDSignIn.m index 7a810445..d9cecb6b 100644 --- a/GoogleSignIn/Sources/GIDSignIn.m +++ b/GoogleSignIn/Sources/GIDSignIn.m @@ -187,8 +187,8 @@ - (BOOL)hasPreviousSignIn { return [authState isAuthorized]; } -- (void)restorePreviousSignInWithCompletion:(nullable GIDSignInCompletion)completion { - [self signInWithOptions:[GIDSignInInternalOptions silentOptionsWithCompletion:completion]]; +- (void)restorePreviousSignInWithCallback:(nullable GIDSignInCallback)callback { + [self signInWithOptions:[GIDSignInInternalOptions silentOptionsWithCallback:callback]]; } - (BOOL)restorePreviousSignInNoRefresh { @@ -217,13 +217,13 @@ - (BOOL)restorePreviousSignInNoRefresh { - (void)signInWithConfiguration:(GIDConfiguration *)configuration presentingViewController:(UIViewController *)presentingViewController hint:(nullable NSString *)hint - completion:(nullable GIDSignInCompletion)completion { + callback:(nullable GIDSignInCallback)callback { GIDSignInInternalOptions *options = [GIDSignInInternalOptions defaultOptionsWithConfiguration:configuration presentingViewController:presentingViewController loginHint:hint - addScopesFlow:NO - completion:completion]; + addScopesFlow:NO + callback:callback]; [self signInWithOptions:options]; } @@ -231,38 +231,38 @@ - (void)signInWithConfiguration:(GIDConfiguration *)configuration presentingViewController:(UIViewController *)presentingViewController hint:(nullable NSString *)hint additionalScopes:(nullable NSArray *)additionalScopes - completion:(nullable GIDSignInCompletion)completion { + callback:(nullable GIDSignInCallback)callback { GIDSignInInternalOptions *options = [GIDSignInInternalOptions defaultOptionsWithConfiguration:configuration presentingViewController:presentingViewController loginHint:hint addScopesFlow:NO scopes:additionalScopes - completion:completion]; + callback:callback]; [self signInWithOptions:options]; } - (void)signInWithConfiguration:(GIDConfiguration *)configuration presentingViewController:(UIViewController *)presentingViewController - completion:(nullable GIDSignInCompletion)completion { + callback:(nullable GIDSignInCallback)callback { [self signInWithConfiguration:configuration presentingViewController:presentingViewController hint:nil - completion:completion]; + callback:callback]; } - (void)addScopes:(NSArray *)scopes presentingViewController:(UIViewController *)presentingViewController - completion:(nullable GIDSignInCompletion)completion { + 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]; - if (completion) { + if (callback) { dispatch_async(dispatch_get_main_queue(), ^{ - completion(nil, error); + callback(nil, error); }); } return; @@ -278,7 +278,7 @@ - (void)addScopes:(NSArray *)scopes presentingViewController:presentingViewController loginHint:self.currentUser.profile.email addScopesFlow:YES - completion:completion]; + callback:callback]; NSSet *requestedScopes = [NSSet setWithArray:scopes]; NSMutableSet *grantedScopes = @@ -290,9 +290,9 @@ - (void)addScopes:(NSArray *)scopes NSError *error = [NSError errorWithDomain:kGIDSignInErrorDomain code:kGIDSignInErrorCodeScopesAlreadyGranted userInfo:nil]; - if (completion) { + if (callback) { dispatch_async(dispatch_get_main_queue(), ^{ - completion(nil, error); + callback(nil, error); }); } return; @@ -310,52 +310,52 @@ - (void)addScopes:(NSArray *)scopes - (void)signInWithConfiguration:(GIDConfiguration *)configuration presentingWindow:(NSWindow *)presentingWindow hint:(nullable NSString *)hint - completion:(nullable GIDSignInCompletion)completion { + callback:(nullable GIDSignInCallback)callback { GIDSignInInternalOptions *options = [GIDSignInInternalOptions defaultOptionsWithConfiguration:configuration presentingWindow:presentingWindow loginHint:hint - addScopesFlow:NO - completion:completion]; + addScopesFlow:NO + callback:callback]; [self signInWithOptions:options]; } - (void)signInWithConfiguration:(GIDConfiguration *)configuration presentingWindow:(NSWindow *)presentingWindow - completion:(nullable GIDSignInCompletion)completion { + callback:(nullable GIDSignInCallback)callback { [self signInWithConfiguration:configuration presentingWindow:presentingWindow hint:nil - completion:completion]; + callback:callback]; } - (void)signInWithConfiguration:(GIDConfiguration *)configuration presentingWindow:(NSWindow *)presentingWindow hint:(nullable NSString *)hint additionalScopes:(nullable NSArray *)additionalScopes - completion:(nullable GIDSignInCompletion)completion { + callback:(nullable GIDSignInCallback)callback { GIDSignInInternalOptions *options = [GIDSignInInternalOptions defaultOptionsWithConfiguration:configuration presentingWindow:presentingWindow loginHint:hint addScopesFlow:NO scopes:additionalScopes - completion:completion]; + callback:callback]; [self signInWithOptions:options]; } - (void)addScopes:(NSArray *)scopes - presentingWindow:(NSWindow *)presentingWindow - completion:(nullable GIDSignInCompletion)completion { + presentingWindow:(NSWindow *)presentingWindow + 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]; - if (completion) { + if (callback) { dispatch_async(dispatch_get_main_queue(), ^{ - completion(nil, error); + callback(nil, error); }); } return; @@ -371,7 +371,7 @@ - (void)addScopes:(NSArray *)scopes presentingWindow:presentingWindow loginHint:self.currentUser.profile.email addScopesFlow:YES - completion:completion]; + callback:callback]; NSSet *requestedScopes = [NSSet setWithArray:scopes]; NSMutableSet *grantedScopes = @@ -383,9 +383,9 @@ - (void)addScopes:(NSArray *)scopes NSError *error = [NSError errorWithDomain:kGIDSignInErrorDomain code:kGIDSignInErrorCodeScopesAlreadyGranted userInfo:nil]; - if (completion) { + if (callback) { dispatch_async(dispatch_get_main_queue(), ^{ - completion(nil, error); + callback(nil, error); }); } return; @@ -411,7 +411,7 @@ - (void)signOut { [self removeAllKeychainEntries]; } -- (void)disconnectWithCompletion:(nullable GIDDisconnectCompletion)completion { +- (void)disconnectWithCallback:(nullable GIDDisconnectCallback)callback { GIDGoogleUser *user = _currentUser; OIDAuthState *authState = user.authentication.authState; if (!authState) { @@ -428,9 +428,9 @@ - (void)disconnectWithCompletion:(nullable GIDDisconnectCompletion)completion { if (!token) { [self signOut]; // Nothing to do here, consider the operation successful. - if (completion) { + if (callback) { dispatch_async(dispatch_get_main_queue(), ^{ - completion(nil); + callback(nil); }); } return; @@ -453,9 +453,9 @@ - (void)disconnectWithCompletion:(nullable GIDDisconnectCompletion)completion { if (!error) { [self signOut]; } - if (completion) { + if (callback) { dispatch_async(dispatch_get_main_queue(), ^{ - completion(error); + callback(error); }); } }]; @@ -538,10 +538,10 @@ - (void)signInWithOptions:(GIDSignInInternalOptions *)options { if (error) { [self authenticateWithOptions:options]; } else { - if (options.completion) { + if (options.callback) { self->_currentOptions = nil; dispatch_async(dispatch_get_main_queue(), ^{ - options.completion(self->_currentUser, nil); + options.callback(self->_currentUser, nil); }); } } @@ -707,10 +707,10 @@ - (void)authenticateWithOptions:(GIDSignInInternalOptions *)options { NSError *error = [NSError errorWithDomain:kGIDSignInErrorDomain code:kGIDSignInErrorCodeHasNoAuthInKeychain userInfo:nil]; - if (options.completion) { + if (options.callback) { _currentOptions = nil; dispatch_async(dispatch_get_main_queue(), ^{ - options.completion(nil, error); + options.callback(nil, error); }); } return; @@ -881,11 +881,11 @@ - (void)addCompletionCallback:(GIDAuthFlow *)authFlow { __weak GIDAuthFlow *weakAuthFlow = authFlow; [authFlow addCallback:^() { GIDAuthFlow *handlerAuthFlow = weakAuthFlow; - if (self->_currentOptions.completion) { - GIDSignInCompletion completion = self->_currentOptions.completion; + if (self->_currentOptions.callback) { + GIDSignInCallback callback = self->_currentOptions.callback; self->_currentOptions = nil; dispatch_async(dispatch_get_main_queue(), ^{ - completion(self->_currentUser, handlerAuthFlow.error); + callback(self->_currentUser, handlerAuthFlow.error); }); } }]; diff --git a/GoogleSignIn/Sources/GIDSignInInternalOptions.h b/GoogleSignIn/Sources/GIDSignInInternalOptions.h index d104246e..72f9b7fa 100644 --- a/GoogleSignIn/Sources/GIDSignInInternalOptions.h +++ b/GoogleSignIn/Sources/GIDSignInInternalOptions.h @@ -54,8 +54,8 @@ NS_ASSUME_NONNULL_BEGIN @property(nonatomic, readonly, weak, nullable) NSWindow *presentingWindow; #endif // TARGET_OS_IOS || TARGET_OS_MACCATALYST -/// The completion block to be called at the completion of the flow. -@property(nonatomic, readonly, nullable) GIDSignInCompletion completion; +/// The callback block to be called at the completion of the flow. +@property(nonatomic, readonly, nullable) GIDSignInCallback callback; /// The scopes to be used during the flow. @property(nonatomic, copy, nullable) NSArray *scopes; @@ -69,32 +69,32 @@ NS_ASSUME_NONNULL_BEGIN presentingViewController:(nullable UIViewController *)presentingViewController loginHint:(nullable NSString *)loginHint addScopesFlow:(BOOL)addScopesFlow - completion:(nullable GIDSignInCompletion)completion; + callback:(nullable GIDSignInCallback)callback; + (instancetype)defaultOptionsWithConfiguration:(nullable GIDConfiguration *)configuration presentingViewController:(nullable UIViewController *)presentingViewController loginHint:(nullable NSString *)loginHint addScopesFlow:(BOOL)addScopesFlow scopes:(nullable NSArray *)scopes - completion:(nullable GIDSignInCompletion)completion; + callback:(nullable GIDSignInCallback)callback; #elif TARGET_OS_OSX + (instancetype)defaultOptionsWithConfiguration:(nullable GIDConfiguration *)configuration presentingWindow:(nullable NSWindow *)presentingWindow loginHint:(nullable NSString *)loginHint addScopesFlow:(BOOL)addScopesFlow - completion:(nullable GIDSignInCompletion)completion; + callback:(nullable GIDSignInCallback)callback; + (instancetype)defaultOptionsWithConfiguration:(nullable GIDConfiguration *)configuration presentingWindow:(nullable NSWindow *)presentingWindow loginHint:(nullable NSString *)loginHint addScopesFlow:(BOOL)addScopesFlow scopes:(nullable NSArray *)scopes - completion:(nullable GIDSignInCompletion)completion; + callback:(nullable GIDSignInCallback)callback; #endif // TARGET_OS_IOS || TARGET_OS_MACCATALYST /// Creates the options to sign in silently. -+ (instancetype)silentOptionsWithCompletion:(GIDSignInCompletion)completion; ++ (instancetype)silentOptionsWithCallback:(GIDSignInCallback)callback; /// Creates options with the same values as the receiver, except for the "extra parameters", and /// continuation flag, which are replaced by the arguments passed to this method. diff --git a/GoogleSignIn/Sources/GIDSignInInternalOptions.m b/GoogleSignIn/Sources/GIDSignInInternalOptions.m index 06db24ab..f4ed1488 100644 --- a/GoogleSignIn/Sources/GIDSignInInternalOptions.m +++ b/GoogleSignIn/Sources/GIDSignInInternalOptions.m @@ -31,14 +31,14 @@ + (instancetype)defaultOptionsWithConfiguration:(nullable GIDConfiguration *)con loginHint:(nullable NSString *)loginHint addScopesFlow:(BOOL)addScopesFlow scopes:(nullable NSArray *)scopes - completion:(nullable GIDSignInCompletion)completion { + callback:(nullable GIDSignInCallback)callback { #elif TARGET_OS_OSX + (instancetype)defaultOptionsWithConfiguration:(nullable GIDConfiguration *)configuration presentingWindow:(nullable NSWindow *)presentingWindow loginHint:(nullable NSString *)loginHint addScopesFlow:(BOOL)addScopesFlow scopes:(nullable NSArray *)scopes - completion:(nullable GIDSignInCompletion)completion { + callback:(nullable GIDSignInCallback)callback { #endif // TARGET_OS_IOS || TARGET_OS_MACCATALYST GIDSignInInternalOptions *options = [[GIDSignInInternalOptions alloc] init]; @@ -53,7 +53,7 @@ + (instancetype)defaultOptionsWithConfiguration:(nullable GIDConfiguration *)con options->_presentingWindow = presentingWindow; #endif // TARGET_OS_IOS || TARGET_OS_MACCATALYST options->_loginHint = loginHint; - options->_completion = completion; + options->_callback = callback; options->_scopes = [GIDScopes scopesWithBasicProfile:scopes]; } return options; @@ -64,13 +64,13 @@ + (instancetype)defaultOptionsWithConfiguration:(nullable GIDConfiguration *)con presentingViewController:(nullable UIViewController *)presentingViewController loginHint:(nullable NSString *)loginHint addScopesFlow:(BOOL)addScopesFlow - completion:(nullable GIDSignInCompletion)completion { + callback:(nullable GIDSignInCallback)callback { #elif TARGET_OS_OSX + (instancetype)defaultOptionsWithConfiguration:(nullable GIDConfiguration *)configuration presentingWindow:(nullable NSWindow *)presentingWindow loginHint:(nullable NSString *)loginHint addScopesFlow:(BOOL)addScopesFlow - completion:(nullable GIDSignInCompletion)completion { + callback:(nullable GIDSignInCallback)callback { #endif // TARGET_OS_IOS || TARGET_OS_MACCATALYST GIDSignInInternalOptions *options = [self defaultOptionsWithConfiguration:configuration #if TARGET_OS_IOS || TARGET_OS_MACCATALYST @@ -81,11 +81,11 @@ + (instancetype)defaultOptionsWithConfiguration:(nullable GIDConfiguration *)con loginHint:loginHint addScopesFlow:addScopesFlow scopes:@[] - completion:completion]; + callback:callback]; return options; } -+ (instancetype)silentOptionsWithCompletion:(GIDSignInCompletion)completion { ++ (instancetype)silentOptionsWithCallback:(GIDSignInCallback)callback { GIDSignInInternalOptions *options = [self defaultOptionsWithConfiguration:nil #if TARGET_OS_IOS || TARGET_OS_MACCATALYST presentingViewController:nil @@ -93,8 +93,8 @@ + (instancetype)silentOptionsWithCompletion:(GIDSignInCompletion)completion { presentingWindow:nil #endif // TARGET_OS_IOS || TARGET_OS_MACCATALYST loginHint:nil - addScopesFlow:NO - completion:completion]; + addScopesFlow:NO + callback:callback]; if (options) { options->_interactive = NO; } @@ -115,7 +115,7 @@ - (instancetype)optionsWithExtraParameters:(NSDictionary *)extraParams options->_presentingWindow = _presentingWindow; #endif // TARGET_OS_IOS || TARGET_OS_MACCATALYST options->_loginHint = _loginHint; - options->_completion = _completion; + options->_callback = _callback; options->_scopes = _scopes; options->_extraParams = [extraParams copy]; } diff --git a/GoogleSignIn/Sources/Public/GoogleSignIn/GIDAuthentication.h b/GoogleSignIn/Sources/Public/GoogleSignIn/GIDAuthentication.h index 13ae1920..b2c75b4e 100644 --- a/GoogleSignIn/Sources/Public/GoogleSignIn/GIDAuthentication.h +++ b/GoogleSignIn/Sources/Public/GoogleSignIn/GIDAuthentication.h @@ -28,10 +28,10 @@ NS_ASSUME_NONNULL_BEGIN -/// A completion block that takes a `GIDAuthentication` or an error if the attempt to refresh tokens +/// A callback block that takes a `GIDAuthentication` or an error if the attempt to refresh tokens /// was unsuccessful. -typedef void (^GIDAuthenticationCompletion)(GIDAuthentication *_Nullable authentication, - NSError *_Nullable error); +typedef void (^GIDAuthenticationAction)(GIDAuthentication *_Nullable authentication, + NSError *_Nullable error); /// This class represents the OAuth 2.0 entities needed for sign-in. @interface GIDAuthentication : NSObject @@ -67,10 +67,9 @@ typedef void (^GIDAuthenticationCompletion)(GIDAuthentication *_Nullable authent /// Get a valid access token and a valid ID token, refreshing them first if they have expired or are /// about to expire. /// -/// @param completion A completion block that takes a `GIDAuthentication` or an error if the attempt -/// to refresh tokens was unsuccessful. The block will be called asynchronously on the main -/// queue. -- (void)doWithFreshTokens:(GIDAuthenticationCompletion)completion; +/// @param action A callback block that takes a `GIDAuthentication` or an error if the attempt to +/// refresh tokens was unsuccessful. The block will be called asynchronously on the main queue. +- (void)doWithFreshTokens:(GIDAuthenticationAction)action; @end diff --git a/GoogleSignIn/Sources/Public/GoogleSignIn/GIDSignIn.h b/GoogleSignIn/Sources/Public/GoogleSignIn/GIDSignIn.h index 35a8a15d..094dffb1 100644 --- a/GoogleSignIn/Sources/Public/GoogleSignIn/GIDSignIn.h +++ b/GoogleSignIn/Sources/Public/GoogleSignIn/GIDSignIn.h @@ -50,12 +50,12 @@ typedef NS_ERROR_ENUM(kGIDSignInErrorDomain, GIDSignInErrorCode) { kGIDSignInErrorCodeScopesAlreadyGranted = -8, }; -/// Represents a completion block that takes a `GIDGoogleUser` on success or an error if the operation +/// Represents a callback block that takes a `GIDGoogleUser` on success or an error if the operation /// was unsuccessful. -typedef void (^GIDSignInCompletion)(GIDGoogleUser *_Nullable user, NSError *_Nullable error); +typedef void (^GIDSignInCallback)(GIDGoogleUser *_Nullable user, NSError *_Nullable error); -/// Represents a completion block that takes an error if the operation was unsuccessful. -typedef void (^GIDDisconnectCompletion)(NSError *_Nullable error); +/// Represents a callback block that takes an error if the operation was unsuccessful. +typedef void (^GIDDisconnectCallback)(NSError *_Nullable error); /// This class signs the user in with Google. /// @@ -91,9 +91,9 @@ typedef void (^GIDDisconnectCompletion)(NSError *_Nullable error); /// Attempts to restore a previously authenticated user without interaction. /// -/// @param completion The `GIDSignInCompletion` block that is called on completion. This block will -/// be called asynchronously on the main queue. -- (void)restorePreviousSignInWithCompletion:(nullable GIDSignInCompletion)completion; +/// @param callback The `GIDSignInCallback` block that is called on completion. This block will be +/// called asynchronously on the main queue. +- (void)restorePreviousSignInWithCallback:(nullable GIDSignInCallback)callback; /// Marks current user as being in the signed out state. - (void)signOut; @@ -101,35 +101,35 @@ typedef void (^GIDDisconnectCompletion)(NSError *_Nullable error); /// Disconnects the current user from the app and revokes previous authentication. If the operation /// succeeds, the OAuth 2.0 token is also removed from keychain. /// -/// @param completion The optional `GIDDisconnectCompletion` block that is called on completion. -/// This block will be called asynchronously on the main queue. -- (void)disconnectWithCompletion:(nullable GIDDisconnectCompletion)completion; +/// @param callback The optional `GIDDisconnectCallback` block that is called on completion. This +/// block will be called asynchronously on the main queue. +- (void)disconnectWithCallback:(nullable GIDDisconnectCallback)callback; #if TARGET_OS_IOS || TARGET_OS_MACCATALYST /// Starts an interactive sign-in flow on iOS using the provided configuration. /// -/// The completion will be called at the end of this process. Any saved sign-in state will be +/// The callback will be called at the end of this process. Any saved sign-in state will be /// replaced by the result of this flow. Note that this method should not be called when the app is /// starting up, (e.g in `application:didFinishLaunchingWithOptions:`); instead use the -/// `restorePreviousSignInWithCompletion:` method to restore a previous sign-in. +/// `restorePreviousSignInWithCallback:` method to restore a previous sign-in. /// /// @param configuration The configuration properties to be used for this flow. /// @param presentingViewController The view controller used to present `SFSafariViewContoller` on /// iOS 9 and 10 and to supply `presentationContextProvider` for `ASWebAuthenticationSession` on /// iOS 13+. -/// @param completion The `GIDSignInCompletion` block that is called on completion. This block will -/// be called asynchronously on the main queue. +/// @param callback The `GIDSignInCallback` block that is called on completion. This block will be +/// called asynchronously on the main queue. - (void)signInWithConfiguration:(GIDConfiguration *)configuration presentingViewController:(UIViewController *)presentingViewController - completion:(nullable GIDSignInCompletion)completion + callback:(nullable GIDSignInCallback)callback NS_EXTENSION_UNAVAILABLE("The sign-in flow is not supported in App Extensions."); -/// Starts an interactive sign-in flow on iOS using the provided configuration and a login hint. +/// Starts an interactive sign-in flow on iOS using the provided configuration and a login hint. /// -/// The completion will be called at the end of this process. Any saved sign-in state will be +/// The callback will be called at the end of this process. Any saved sign-in state will be /// replaced by the result of this flow. Note that this method should not be called when the app is /// starting up, (e.g in `application:didFinishLaunchingWithOptions:`); instead use the -/// `restorePreviousSignInWithCompletion:` method to restore a previous sign-in. +/// `restorePreviousSignInWithCallback:` method to restore a previous sign-in. /// /// @param configuration The configuration properties to be used for this flow. /// @param presentingViewController The view controller used to present `SFSafariViewContoller` on @@ -137,20 +137,20 @@ typedef void (^GIDDisconnectCompletion)(NSError *_Nullable error); /// iOS 13+. /// @param hint An optional hint for the authorization server, for example the user's ID or email /// address, to be prefilled if possible. -/// @param completion The `GIDSignInCompletion` block that is called on completion. This block will -/// be called asynchronously on the main queue. +/// @param callback The `GIDSignInCallback` block that is called on completion. This block will be +/// called asynchronously on the main queue. - (void)signInWithConfiguration:(GIDConfiguration *)configuration presentingViewController:(UIViewController *)presentingViewController hint:(nullable NSString *)hint - completion:(nullable GIDSignInCompletion)completion + callback:(nullable GIDSignInCallback)callback NS_EXTENSION_UNAVAILABLE("The sign-in flow is not supported in App Extensions."); /// Starts an interactive sign-in flow on iOS using the provided configuration and a login hint. /// -/// The completion will be called at the end of this process. Any saved sign-in state will be +/// The callback will be called at the end of this process. Any saved sign-in state will be /// replaced by the result of this flow. Note that this method should not be called when the app is /// starting up, (e.g in `application:didFinishLaunchingWithOptions:`); instead use the -/// `restorePreviousSignInWithCompletion:` method to restore a previous sign-in. +/// `restorePreviousSignInWithCallback:` method to restore a previous sign-in. /// /// @param configuration The configuration properties to be used for this flow. /// @param presentingViewController The view controller used to present `SFSafariViewContoller` on @@ -158,98 +158,98 @@ typedef void (^GIDDisconnectCompletion)(NSError *_Nullable error); /// @param hint An optional hint for the authorization server, for example the user's ID or email /// address, to be prefilled if possible. /// @param additionalScopes An optional array of scopes to request in addition to the basic profile scopes. -/// @param completion The `GIDSignInCompletion` block that is called on completion. This block will -/// be called asynchronously on the main queue. +/// @param callback The `GIDSignInCallback` block that is called on completion. This block will be +/// called asynchronously on the main queue. - (void)signInWithConfiguration:(GIDConfiguration *)configuration presentingViewController:(UIViewController *)presentingViewController hint:(nullable NSString *)hint additionalScopes:(nullable NSArray *)additionalScopes - completion:(nullable GIDSignInCompletion)completion; + callback:(nullable GIDSignInCallback)callback; /// Starts an interactive consent flow on iOS to add scopes to the current user's grants. /// -/// The completion will be called at the end of this process. If successful, a new `GIDGoogleUser` +/// The callback will be called at the end of this process. If successful, a new `GIDGoogleUser` /// instance will be returned reflecting the new scopes and saved sign-in state will be updated. /// /// @param scopes The scopes to ask the user to consent to. /// @param presentingViewController The view controller used to present `SFSafariViewContoller` on /// iOS 9 and 10 and to supply `presentationContextProvider` for `ASWebAuthenticationSession` on /// iOS 13+. -/// @param completion The `GIDSignInCompletion` block that is called on completion. This block will -/// be called asynchronously on the main queue. +/// @param callback The `GIDSignInCallback` block that is called on completion. This block will be +/// called asynchronously on the main queue. - (void)addScopes:(NSArray *)scopes presentingViewController:(UIViewController *)presentingViewController - completion:(nullable GIDSignInCompletion)completion + callback:(nullable GIDSignInCallback)callback NS_EXTENSION_UNAVAILABLE("The add scopes flow is not supported in App Extensions."); #elif TARGET_OS_OSX /// Starts an interactive sign-in flow on macOS using the provided configuration. /// -/// The completion will be called at the end of this process. Any saved sign-in state will be +/// The callback will be called at the end of this process. Any saved sign-in state will be /// replaced by the result of this flow. Note that this method should not be called when the app is /// starting up, (e.g in `application:didFinishLaunchingWithOptions:`); instead use the -/// `restorePreviousSignInWithCompletion:` method to restore a previous sign-in. +/// `restorePreviousSignInWithCallback:` method to restore a previous sign-in. /// /// @param configuration The configuration properties to be used for this flow. /// @param presentingWindow The window used to supply `presentationContextProvider` for `ASWebAuthenticationSession`. -/// @param completion The `GIDSignInCompletion` block that is called on completion. This block will -/// be called asynchronously on the main queue. +/// @param callback The `GIDSignInCallback` block that is called on completion. This block will be +/// called asynchronously on the main queue. - (void)signInWithConfiguration:(GIDConfiguration *)configuration presentingWindow:(NSWindow *)presentingWindow - completion:(nullable GIDSignInCompletion)completion; + callback:(nullable GIDSignInCallback)callback; /// Starts an interactive sign-in flow on macOS using the provided configuration and a login hint. /// -/// The completion will be called at the end of this process. Any saved sign-in state will be +/// The callback will be called at the end of this process. Any saved sign-in state will be /// replaced by the result of this flow. Note that this method should not be called when the app is /// starting up, (e.g in `application:didFinishLaunchingWithOptions:`); instead use the -/// `restorePreviousSignInWithCompletion:` method to restore a previous sign-in. +/// `restorePreviousSignInWithCallback:` method to restore a previous sign-in. /// /// @param configuration The configuration properties to be used for this flow. /// @param presentingWindow The window used to supply `presentationContextProvider` for `ASWebAuthenticationSession`. /// @param hint An optional hint for the authorization server, for example the user's ID or email /// address, to be prefilled if possible. -/// @param completion The `GIDSignInCompletion` block that is called on completion. This block will -/// be called asynchronously on the main queue. +/// @param callback The `GIDSignInCallback` block that is called on completion. This block will be +/// called asynchronously on the main queue. - (void)signInWithConfiguration:(GIDConfiguration *)configuration presentingWindow:(NSWindow *)presentingWindow hint:(nullable NSString *)hint - completion:(nullable GIDSignInCompletion)completion; + callback:(nullable GIDSignInCallback)callback; /// Starts an interactive sign-in flow on macOS using the provided configuration and a login hint. /// -/// The completion will be called at the end of this process. Any saved sign-in state will be +/// The callback will be called at the end of this process. Any saved sign-in state will be /// replaced by the result of this flow. Note that this method should not be called when the app is /// starting up, (e.g in `application:didFinishLaunchingWithOptions:`); instead use the -/// `restorePreviousSignInWithCompletion:` method to restore a previous sign-in. +/// `restorePreviousSignInWithCallback:` method to restore a previous sign-in. /// /// @param configuration The configuration properties to be used for this flow. /// @param presentingWindow The window used to supply `presentationContextProvider` for `ASWebAuthenticationSession`. /// @param hint An optional hint for the authorization server, for example the user's ID or email /// address, to be prefilled if possible. /// @param additionalScopes An optional array of scopes to request in addition to the basic profile scopes. -/// @param completion The `GIDSignInCompletion` block that is called on completion. This block will -/// be called asynchronously on the main queue. +/// @param callback The `GIDSignInCallback` block that is called on completion. This block will be +/// called asynchronously on the main queue. - (void)signInWithConfiguration:(GIDConfiguration *)configuration presentingWindow:(NSWindow *)presentingWindow hint:(nullable NSString *)hint additionalScopes:(nullable NSArray *)additionalScopes - completion:(nullable GIDSignInCompletion)completion; + callback:(nullable GIDSignInCallback)callback; /// Starts an interactive consent flow on macOS to add scopes to the current user's grants. /// -/// The completion will be called at the end of this process. If successful, a new `GIDGoogleUser` +/// The callback will be called at the end of this process. If successful, a new `GIDGoogleUser` /// instance will be returned reflecting the new scopes and saved sign-in state will be updated. /// /// @param scopes An array of scopes to ask the user to consent to. /// @param presentingWindow The window used to supply `presentationContextProvider` for `ASWebAuthenticationSession`. -/// @param completion The `GIDSignInCompletion` block that is called on completion. This block will -/// be called asynchronously on the main queue. +/// @param callback The `GIDSignInCallback` block that is called on completion. This block will be +/// called asynchronously on the main queue. - (void)addScopes:(NSArray *)scopes - presentingWindow:(NSWindow *)presentingWindow - completion:(nullable GIDSignInCompletion)completion; + presentingWindow:(NSWindow *)presentingWindow + callback:(nullable GIDSignInCallback)callback; #endif diff --git a/GoogleSignIn/Tests/Unit/GIDSignInInternalOptionsTest.m b/GoogleSignIn/Tests/Unit/GIDSignInInternalOptionsTest.m index ce98c93a..c786bba6 100644 --- a/GoogleSignIn/Tests/Unit/GIDSignInInternalOptionsTest.m +++ b/GoogleSignIn/Tests/Unit/GIDSignInInternalOptionsTest.m @@ -37,7 +37,7 @@ - (void)testDefaultOptions { id presentingWindow = OCMStrictClassMock([NSWindow class]); #endif // TARGET_OS_IOS || TARGET_OS_MACCATALYST NSString *loginHint = @"login_hint"; - GIDSignInCompletion completion = ^(GIDGoogleUser * _Nullable user, NSError * _Nullable error) {}; + GIDSignInCallback callback = ^(GIDGoogleUser * _Nullable user, NSError * _Nullable error) {}; GIDSignInInternalOptions *options = [GIDSignInInternalOptions defaultOptionsWithConfiguration:configuration @@ -47,8 +47,8 @@ - (void)testDefaultOptions { presentingWindow:presentingWindow #endif // TARGET_OS_IOS || TARGET_OS_MACCATALYST loginHint:loginHint - addScopesFlow:NO - completion:completion]; + addScopesFlow:NO + callback:callback]; XCTAssertTrue(options.interactive); XCTAssertFalse(options.continuation); XCTAssertFalse(options.addScopesFlow); @@ -63,13 +63,12 @@ - (void)testDefaultOptions { } - (void)testSilentOptions { - GIDSignInCompletion completion = ^(GIDGoogleUser * _Nullable user, NSError * _Nullable error) {}; - GIDSignInInternalOptions *options = [GIDSignInInternalOptions - silentOptionsWithCompletion:completion]; + GIDSignInCallback callback = ^(GIDGoogleUser * _Nullable user, NSError * _Nullable error) {}; + GIDSignInInternalOptions *options = [GIDSignInInternalOptions silentOptionsWithCallback:callback]; XCTAssertFalse(options.interactive); XCTAssertFalse(options.continuation); XCTAssertNil(options.extraParams); - XCTAssertEqual(options.completion, completion); + XCTAssertEqual(options.callback, callback); } @end diff --git a/GoogleSignIn/Tests/Unit/GIDSignInTest.m b/GoogleSignIn/Tests/Unit/GIDSignInTest.m index 0a74e01c..070fead1 100644 --- a/GoogleSignIn/Tests/Unit/GIDSignInTest.m +++ b/GoogleSignIn/Tests/Unit/GIDSignInTest.m @@ -217,7 +217,7 @@ @interface GIDSignInTest : XCTestCase { NSError *_authError; // Whether callback block has been called. - BOOL _completionCalled; + BOOL _callbackCalled; // Fake fetcher service to emulate network requests. GIDFakeFetcherService *_fetcherService; @@ -240,8 +240,8 @@ @interface GIDSignInTest : XCTestCase { // The login hint to be used when testing |GIDSignIn|. NSString *_hint; - // The completion to be used when testing |GIDSignIn|. - GIDSignInCompletion _completion; + // The callback to be used when testing |GIDSignIn|. + GIDSignInCallback _callback; // The saved authorization request. OIDAuthorizationRequest *_savedAuthorizationRequest; @@ -283,7 +283,7 @@ - (void)setUp { _saveAuthorizationReturnValue = YES; // States - _completionCalled = NO; + _callbackCalled = NO; _keychainSaved = NO; _keychainRemoved = NO; _changedKeyPaths = [[NSMutableSet alloc] init]; @@ -346,13 +346,13 @@ - (void)setUp { _hint = nil; __weak GIDSignInTest *weakSelf = self; - _completion = ^(GIDGoogleUser * _Nullable user, NSError * _Nullable error) { + _callback = ^(GIDGoogleUser * _Nullable user, NSError * _Nullable error) { GIDSignInTest *strongSelf = weakSelf; if (!user) { XCTAssertNotNil(error, @"should have an error if user is nil"); } - XCTAssertFalse(strongSelf->_completionCalled, @"callback already called"); - strongSelf->_completionCalled = YES; + XCTAssertFalse(strongSelf->_callbackCalled, @"callback already called"); + strongSelf->_callbackCalled = YES; strongSelf->_authError = error; }; @@ -434,7 +434,7 @@ - (void)testHasPreviousSignIn_HasBeenAuthenticated { [_authorization verify]; [_authState verify]; XCTAssertFalse(_keychainRemoved, @"should not remove keychain"); - XCTAssertFalse(_completionCalled, @"should not call delegate"); + XCTAssertFalse(_callbackCalled, @"should not call delegate"); XCTAssertNil(_authError, @"should have no error"); } @@ -445,19 +445,19 @@ - (void)testHasPreviousSignIn_HasNotBeenAuthenticated { [_authorization verify]; [_authState verify]; XCTAssertFalse(_keychainRemoved, @"should not remove keychain"); - XCTAssertFalse(_completionCalled, @"should not call delegate"); + XCTAssertFalse(_callbackCalled, @"should not call delegate"); } - (void)testRestorePreviousSignInWhenSignedOut { [[[_authorization expect] andReturn:_authState] authState]; [[[_authState expect] andReturnValue:[NSNumber numberWithBool:NO]] isAuthorized]; - _completionCalled = NO; + _callbackCalled = NO; _authError = nil; XCTestExpectation *expectation = [self expectationWithDescription:@"Callback should be called."]; - [_signIn restorePreviousSignInWithCompletion:^(GIDGoogleUser * _Nullable user, - NSError * _Nullable error) { + [_signIn restorePreviousSignInWithCallback:^(GIDGoogleUser * _Nullable user, + NSError * _Nullable error) { [expectation fulfill]; XCTAssertNotNil(error, @"error should not have been nil"); XCTAssertEqual(error.domain, @@ -670,7 +670,7 @@ - (void)testOAuthLogin_ConsentCanceled { oldAccessToken:NO modalCancel:NO]; [self waitForExpectationsWithTimeout:1 handler:nil]; - XCTAssertTrue(_completionCalled, @"should call delegate"); + XCTAssertTrue(_callbackCalled, @"should call delegate"); XCTAssertEqual(_authError.code, kGIDSignInErrorCodeCanceled); } @@ -684,7 +684,7 @@ - (void)testOAuthLogin_ModalCanceled { oldAccessToken:NO modalCancel:YES]; [self waitForExpectationsWithTimeout:1 handler:nil]; - XCTAssertTrue(_completionCalled, @"should call delegate"); + XCTAssertTrue(_callbackCalled, @"should call delegate"); XCTAssertEqual(_authError.code, kGIDSignInErrorCodeCanceled); } @@ -699,7 +699,7 @@ - (void)testOAuthLogin_KeychainError { modalCancel:NO]; [self waitForExpectationsWithTimeout:1 handler:nil]; XCTAssertFalse(_keychainSaved, @"should save to keychain"); - XCTAssertTrue(_completionCalled, @"should call delegate"); + XCTAssertTrue(_callbackCalled, @"should call delegate"); XCTAssertEqualObjects(_authError.domain, kGIDSignInErrorDomain); XCTAssertEqual(_authError.code, kGIDSignInErrorCodeKeychain); } @@ -731,13 +731,13 @@ - (void)testNotHandleWrongScheme { XCTAssertFalse([_signIn handleURL:[NSURL URLWithString:kWrongSchemeURL]], @"should not handle URL"); XCTAssertFalse(_keychainSaved, @"should not save to keychain"); - XCTAssertFalse(_completionCalled, @"should not call delegate"); + XCTAssertFalse(_callbackCalled, @"should not call delegate"); } - (void)testNotHandleWrongPath { XCTAssertFalse([_signIn handleURL:[NSURL URLWithString:kWrongPathURL]], @"should not handle URL"); XCTAssertFalse(_keychainSaved, @"should not save to keychain"); - XCTAssertFalse(_completionCalled, @"should not call delegate"); + XCTAssertFalse(_callbackCalled, @"should not call delegate"); } #pragma mark - Tests - disconnectWithCallback: @@ -750,7 +750,7 @@ - (void)testDisconnect_accessToken { [[[_authorization expect] andReturn:_fetcherService] fetcherService]; XCTestExpectation *expectation = [self expectationWithDescription:@"Callback called with nil error"]; - [_signIn disconnectWithCompletion:^(NSError * _Nullable error) { + [_signIn disconnectWithCallback:^(NSError * _Nullable error) { if (error == nil) { [expectation fulfill]; } @@ -767,7 +767,7 @@ - (void)testDisconnectNoCallback_accessToken { [[[_authState expect] andReturn:_tokenResponse] lastTokenResponse]; [[[_tokenResponse expect] andReturn:kAccessToken] accessToken]; [[[_authorization expect] andReturn:_fetcherService] fetcherService]; - [_signIn disconnectWithCompletion:nil]; + [_signIn disconnectWithCallback:nil]; [self verifyAndRevokeToken:kAccessToken hasCallback:NO]; [_authorization verify]; [_authState verify]; @@ -784,7 +784,7 @@ - (void)testDisconnect_refreshToken { [[[_authorization expect] andReturn:_fetcherService] fetcherService]; XCTestExpectation *expectation = [self expectationWithDescription:@"Callback called with nil error"]; - [_signIn disconnectWithCompletion:^(NSError * _Nullable error) { + [_signIn disconnectWithCallback:^(NSError * _Nullable error) { if (error == nil) { [expectation fulfill]; } @@ -803,7 +803,7 @@ - (void)testDisconnect_errors { [[[_authorization expect] andReturn:_fetcherService] fetcherService]; XCTestExpectation *expectation = [self expectationWithDescription:@"Callback called with an error"]; - [_signIn disconnectWithCompletion:^(NSError * _Nullable error) { + [_signIn disconnectWithCallback:^(NSError * _Nullable error) { if (error != nil) { [expectation fulfill]; } @@ -824,7 +824,7 @@ - (void)testDisconnectNoCallback_errors { [[[_authState expect] andReturn:_tokenResponse] lastTokenResponse]; [[[_tokenResponse expect] andReturn:kAccessToken] accessToken]; [[[_authorization expect] andReturn:_fetcherService] fetcherService]; - [_signIn disconnectWithCompletion:nil]; + [_signIn disconnectWithCallback:nil]; XCTAssertTrue([self isFetcherStarted], @"should start fetching"); // Emulate result back from server. NSError *error = [self error]; @@ -844,7 +844,7 @@ - (void)testDisconnect_noTokens { [[[_tokenResponse expect] andReturn:nil] refreshToken]; XCTestExpectation *expectation = [self expectationWithDescription:@"Callback called with nil error"]; - [_signIn disconnectWithCompletion:^(NSError * _Nullable error) { + [_signIn disconnectWithCallback:^(NSError * _Nullable error) { if (error == nil) { [expectation fulfill]; } @@ -864,7 +864,7 @@ - (void)testDisconnectNoCallback_noTokens { [[[_tokenResponse expect] andReturn:nil] accessToken]; [[[_authState expect] andReturn:_tokenResponse] lastTokenResponse]; [[[_tokenResponse expect] andReturn:nil] refreshToken]; - [_signIn disconnectWithCompletion:nil]; + [_signIn disconnectWithCallback:nil]; XCTAssertFalse([self isFetcherStarted], @"should not fetch"); XCTAssertTrue(_keychainRemoved, @"keychain should be removed"); [_authorization verify]; @@ -887,7 +887,7 @@ - (void)testPresentingViewControllerException { presentingWindow:_presentingWindow #endif // TARGET_OS_IOS || TARGET_OS_MACCATALYST hint:_hint - completion:_completion]); + callback:_callback]); } - (void)testClientIDMissingException { @@ -903,7 +903,7 @@ - (void)testClientIDMissingException { #elif TARGET_OS_OSX presentingWindow:_presentingWindow #endif // TARGET_OS_IOS || TARGET_OS_MACCATALYST - completion:nil]; + callback:nil]; } @catch (NSException *exception) { threw = YES; XCTAssertEqualObjects(exception.description, @@ -924,7 +924,7 @@ - (void)testSchemesNotSupportedException { presentingWindow:_presentingWindow #endif // TARGET_OS_IOS || TARGET_OS_MACCATALYST hint:_hint - completion:_completion]; + callback:_callback]; } @catch (NSException *exception) { threw = YES; XCTAssertEqualObjects(exception.description, @@ -1040,7 +1040,7 @@ - (void)testAuthEndpointEMMError { [self waitForExpectationsWithTimeout:1 handler:nil]; XCTAssertFalse(_keychainSaved, @"should not save to keychain"); - XCTAssertTrue(_completionCalled, @"should call delegate"); + XCTAssertTrue(_callbackCalled, @"should call delegate"); XCTAssertNotNil(_authError, @"should have error"); XCTAssertEqualObjects(_authError.domain, kGIDSignInErrorDomain); XCTAssertEqual(_authError.code, kGIDSignInErrorCodeEMM); @@ -1079,7 +1079,7 @@ - (void)testTokenEndpointEMMError { [_authentication verify]; XCTAssertFalse(_keychainSaved, @"should not save to keychain"); - XCTAssertTrue(_completionCalled, @"should call delegate"); + XCTAssertTrue(_callbackCalled, @"should call delegate"); XCTAssertNotNil(_authError, @"should have error"); XCTAssertEqualObjects(_authError.domain, kGIDSignInErrorDomain); XCTAssertEqual(_authError.code, kGIDSignInErrorCodeEMM); @@ -1220,13 +1220,13 @@ - (void)OAuthLoginWithAddScopesFlow:(BOOL)addScopesFlow } } else { XCTestExpectation *expectation = [self expectationWithDescription:@"Callback called"]; - GIDSignInCompletion completion = ^(GIDGoogleUser * _Nullable user, NSError * _Nullable error) { + GIDSignInCallback callback = ^(GIDGoogleUser * _Nullable user, NSError * _Nullable error) { [expectation fulfill]; if (!user) { XCTAssertNotNil(error, @"should have an error if user is nil"); } - XCTAssertFalse(self->_completionCalled, @"callback already called"); - self->_completionCalled = YES; + XCTAssertFalse(self->_callbackCalled, @"callback already called"); + self->_callbackCalled = YES; self->_authError = error; }; if (addScopesFlow) { @@ -1236,7 +1236,7 @@ - (void)OAuthLoginWithAddScopesFlow:(BOOL)addScopesFlow #elif TARGET_OS_OSX presentingWindow:_presentingWindow #endif // TARGET_OS_IOS || TARGET_OS_MACCATALYST - completion:completion]; + callback:callback]; } else { if (useAdditionalScopes) { [_signIn signInWithConfiguration:_configuration @@ -1247,7 +1247,7 @@ - (void)OAuthLoginWithAddScopesFlow:(BOOL)addScopesFlow #endif // TARGET_OS_IOS || TARGET_OS_MACCATALYST hint:_hint additionalScopes:additionalScopes - completion:completion]; + callback:callback]; } else { [_signIn signInWithConfiguration:_configuration #if TARGET_OS_IOS || TARGET_OS_MACCATALYST @@ -1256,7 +1256,7 @@ - (void)OAuthLoginWithAddScopesFlow:(BOOL)addScopesFlow presentingWindow:_presentingWindow #endif // TARGET_OS_IOS || TARGET_OS_MACCATALYST hint:_hint - completion:completion]; + callback:callback]; } } @@ -1305,8 +1305,8 @@ - (void)OAuthLoginWithAddScopesFlow:(BOOL)addScopesFlow if (restoredSignIn && oldAccessToken) { XCTestExpectation *expectation = [self expectationWithDescription:@"Callback should be called"]; - [_signIn restorePreviousSignInWithCompletion:^(GIDGoogleUser * _Nullable user, - NSError * _Nullable error) { + [_signIn restorePreviousSignInWithCallback:^(GIDGoogleUser * _Nullable user, + NSError * _Nullable error) { [expectation fulfill]; XCTAssertNil(error, @"should have no error"); }]; @@ -1351,8 +1351,8 @@ - (void)OAuthLoginWithAddScopesFlow:(BOOL)addScopesFlow if (restoredSignIn && !oldAccessToken) { XCTestExpectation *expectation = [self expectationWithDescription:@"Callback should be called"]; - [_signIn restorePreviousSignInWithCompletion:^(GIDGoogleUser * _Nullable user, - NSError * _Nullable error) { + [_signIn restorePreviousSignInWithCallback:^(GIDGoogleUser * _Nullable user, + NSError * _Nullable error) { [expectation fulfill]; XCTAssertNil(error, @"should have no error"); }]; @@ -1375,7 +1375,7 @@ - (void)OAuthLoginWithAddScopesFlow:(BOOL)addScopesFlow XCTAssertTrue(profileData.hasImage); // If attempt to authenticate again, will reuse existing auth object. - _completionCalled = NO; + _callbackCalled = NO; _keychainRemoved = NO; _keychainSaved = NO; _authError = nil; @@ -1385,18 +1385,18 @@ - (void)OAuthLoginWithAddScopesFlow:(BOOL)addScopesFlow [[[_user expect] andReturn:_authentication] authentication]; } - __block GIDAuthenticationCompletion completion; - [[_authentication expect] doWithFreshTokens:SAVE_TO_ARG_BLOCK(completion)]; + __block GIDAuthenticationAction action; + [[_authentication expect] doWithFreshTokens:SAVE_TO_ARG_BLOCK(action)]; XCTestExpectation *expectation = [self expectationWithDescription:@"Callback should be called"]; - [_signIn restorePreviousSignInWithCompletion:^(GIDGoogleUser * _Nullable user, - NSError * _Nullable error) { + [_signIn restorePreviousSignInWithCallback:^(GIDGoogleUser * _Nullable user, + NSError * _Nullable error) { [expectation fulfill]; XCTAssertNil(error, @"should have no error"); }]; - completion(_authentication, nil); + action(_authentication, nil); [self waitForExpectationsWithTimeout:1 handler:nil]; XCTAssertFalse(_keychainRemoved, @"should not remove keychain"); diff --git a/Samples/ObjC/SignInSample/Source/AppDelegate.m b/Samples/ObjC/SignInSample/Source/AppDelegate.m index de742b5c..45927392 100644 --- a/Samples/ObjC/SignInSample/Source/AppDelegate.m +++ b/Samples/ObjC/SignInSample/Source/AppDelegate.m @@ -30,8 +30,8 @@ - (BOOL)application:(UIApplication *)application // succeeds, we'll have a currentUser and the view will be able to draw its UI for the signed-in // state. If the restore fails, currentUser will be nil and we'll draw the signed-out state // prompting the user to sign in. - [GIDSignIn.sharedInstance restorePreviousSignInWithCompletion:^(GIDGoogleUser *user, - NSError *error) { + [GIDSignIn.sharedInstance restorePreviousSignInWithCallback:^(GIDGoogleUser * _Nullable user, + NSError * _Nullable error) { self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; SignInViewController *masterViewController = [[SignInViewController alloc] initWithNibName:@"SignInViewController" bundle:nil]; diff --git a/Samples/ObjC/SignInSample/Source/SignInViewController.m b/Samples/ObjC/SignInSample/Source/SignInViewController.m index 5f422f6a..009e698c 100644 --- a/Samples/ObjC/SignInSample/Source/SignInViewController.m +++ b/Samples/ObjC/SignInSample/Source/SignInViewController.m @@ -259,7 +259,8 @@ - (void)updateButtons { - (IBAction)signIn:(id)sender { [GIDSignIn.sharedInstance signInWithConfiguration:_configuration presentingViewController:self - completion:^(GIDGoogleUser *user, NSError *error) { + callback:^(GIDGoogleUser * _Nullable user, + NSError * _Nullable error) { if (error) { self->_signInAuthStatus.text = [NSString stringWithFormat:@"Status: Authentication error: %@", error]; @@ -277,7 +278,7 @@ - (IBAction)signOut:(id)sender { } - (IBAction)disconnect:(id)sender { - [GIDSignIn.sharedInstance disconnectWithCompletion:^(NSError *error) { + [GIDSignIn.sharedInstance disconnectWithCallback:^(NSError * _Nullable error) { if (error) { self->_signInAuthStatus.text = [NSString stringWithFormat:@"Status: Failed to disconnect: %@", error]; @@ -292,7 +293,8 @@ - (IBAction)disconnect:(id)sender { - (IBAction)addScopes:(id)sender { [GIDSignIn.sharedInstance addScopes:@[ @"https://www.googleapis.com/auth/user.birthday.read" ] presentingViewController:self - completion:^(GIDGoogleUser *user, NSError *error) { + callback:^(GIDGoogleUser * _Nullable user, + NSError * _Nullable error) { if (error) { self->_signInAuthStatus.text = [NSString stringWithFormat:@"Status: Failed to add scopes: %@", error];