diff --git a/GoogleSignIn/Sources/GIDSignIn.m b/GoogleSignIn/Sources/GIDSignIn.m index 86de6504..f7e6d04c 100644 --- a/GoogleSignIn/Sources/GIDSignIn.m +++ b/GoogleSignIn/Sources/GIDSignIn.m @@ -214,7 +214,7 @@ - (BOOL)restorePreviousSignInNoRefresh { GIDProfileData *profileData = [self profileDataWithIDToken:idToken]; GIDGoogleUser *user = [[GIDGoogleUser alloc] initWithAuthState:authState profileData:profileData]; - [self setCurrentUserWithKVO:user]; + self.currentUser = user; return YES; } @@ -401,9 +401,7 @@ - (void)addScopes:(NSArray *)scopes - (void)signOut { // Clear the current user if there is one. if (_currentUser) { - [self willChangeValueForKey:NSStringFromSelector(@selector(currentUser))]; - _currentUser = nil; - [self didChangeValueForKey:NSStringFromSelector(@selector(currentUser))]; + self.currentUser = nil; } // Remove all state from the keychain. [self removeAllKeychainEntries]; @@ -803,7 +801,7 @@ - (void)addSaveAuthCallback:(GIDAuthFlow *)authFlow { } else { GIDGoogleUser *user = [[GIDGoogleUser alloc] initWithAuthState:authState profileData:handlerAuthFlow.profileData]; - [self setCurrentUserWithKVO:user]; + self.currentUser = user; } } }]; @@ -935,17 +933,6 @@ - (BOOL)handleDevicePolicyAppURL:(NSURL *)url { return YES; } -#pragma mark - Key-Value Observing - -// Override |NSObject(NSKeyValueObservingCustomization)| method in order to provide custom KVO -// notifications for the |currentUser| property. -+ (BOOL)automaticallyNotifiesObserversForKey:(NSString *)key { - if ([key isEqual:NSStringFromSelector(@selector(currentUser))]) { - return NO; - } - return [super automaticallyNotifiesObserversForKey:key]; -} - #pragma mark - Helpers - (NSError *)errorWithString:(NSString *)errorString code:(GIDSignInErrorCode)code { @@ -1035,13 +1022,6 @@ - (GIDProfileData *)profileDataWithIDToken:(OIDIDToken *)idToken { imageURL:[NSURL URLWithString:idToken.claims[kBasicProfilePictureKey]]]; } -// Set currentUser making appropriate KVO calls. -- (void)setCurrentUserWithKVO:(GIDGoogleUser *_Nullable)user { - [self willChangeValueForKey:NSStringFromSelector(@selector(currentUser))]; - _currentUser = user; - [self didChangeValueForKey:NSStringFromSelector(@selector(currentUser))]; -} - // Try to retrieve a configuration value from an |NSBundle|'s Info.plist for a given key. + (nullable NSString *)configValueFromBundle:(NSBundle *)bundle forKey:(NSString *)key { NSString *value; diff --git a/GoogleSignIn/Sources/GIDSignIn_Private.h b/GoogleSignIn/Sources/GIDSignIn_Private.h index 5d1a6da5..74b4b636 100644 --- a/GoogleSignIn/Sources/GIDSignIn_Private.h +++ b/GoogleSignIn/Sources/GIDSignIn_Private.h @@ -24,6 +24,9 @@ NS_ASSUME_NONNULL_BEGIN // Private |GIDSignIn| methods that are used internally in this SDK and other Google SDKs. @interface GIDSignIn () +// Redeclare |currentUser| as readwrite for internal use. +@property(nonatomic, readwrite, nullable) GIDGoogleUser *currentUser; + // Private initializer for |GIDSignIn|. - (instancetype)initPrivate; diff --git a/GoogleSignIn/Tests/Unit/GIDSignInTest.m b/GoogleSignIn/Tests/Unit/GIDSignInTest.m index 61f18f41..01bb447a 100644 --- a/GoogleSignIn/Tests/Unit/GIDSignInTest.m +++ b/GoogleSignIn/Tests/Unit/GIDSignInTest.m @@ -153,9 +153,6 @@ static NSString *const kGrantedScope = @"grantedScope"; static NSString *const kNewScope = @"newScope"; -/// Unique pointer value for KVO tests. -static void *kTestObserverContext = &kTestObserverContext; - #if TARGET_OS_IOS || TARGET_OS_MACCATALYST // This category is used to allow the test to swizzle a private method. @interface UIViewController (Testing) @@ -263,9 +260,6 @@ @interface GIDSignInTest : XCTestCase { // The saved token request callback. OIDTokenCallback _savedTokenCallback; - // Set of all |GIDSignIn| key paths which were observed to change. - NSMutableSet *_changedKeyPaths; - // Status returned by saveAuthorization:toKeychainForName: BOOL _saveAuthorizationReturnValue; } @@ -286,7 +280,6 @@ - (void)setUp { _completionCalled = NO; _keychainSaved = NO; _keychainRemoved = NO; - _changedKeyPaths = [[NSMutableSet alloc] init]; // Mocks #if TARGET_OS_IOS || TARGET_OS_MACCATALYST @@ -354,11 +347,6 @@ - (void)setUp { strongSelf->_completionCalled = YES; strongSelf->_authError = error; }; - - [_signIn addObserver:self - forKeyPath:NSStringFromSelector(@selector(currentUser)) - options:0 - context:kTestObserverContext]; } - (void)tearDown { @@ -379,10 +367,6 @@ - (void)tearDown { [_fakeMainBundle stopFaking]; [super tearDown]; - - [_signIn removeObserver:self - forKeyPath:NSStringFromSelector(@selector(currentUser)) - context:kTestObserverContext]; } #pragma mark - Tests @@ -759,8 +743,6 @@ - (void)testSignOut { [_signIn signOut]; XCTAssertNil(_signIn.currentUser, @"should not have a current user"); XCTAssertTrue(_keychainRemoved, @"should remove keychain"); - XCTAssertTrue([_changedKeyPaths containsObject:NSStringFromSelector(@selector(currentUser))], - @"should notify observers that signed in user changed"); OCMVerify([_authorization removeAuthorizationFromKeychainForName:kKeychainName useDataProtectionKeychain:YES]); @@ -1445,16 +1427,4 @@ - (void)OAuthLoginWithAddScopesFlow:(BOOL)addScopesFlow } } - -#pragma mark - Key Value Observing - -- (void)observeValueForKeyPath:(NSString *)keyPath - ofObject:(id)object - change:(NSDictionary *)change - context:(void *)context { - if (context == kTestObserverContext && object == _signIn) { - [_changedKeyPaths addObject:keyPath]; - } -} - @end