From 6f64b8e5d6abbadb2bd21cbdb9eaf75f7e2f871e Mon Sep 17 00:00:00 2001 From: Stephan Diederich Date: Fri, 6 Sep 2013 17:24:01 +0200 Subject: [PATCH] make installationIdentification KVO'able --- Classes/BITAuthenticator.h | 3 ++- Classes/BITAuthenticator.m | 2 ++ .../HockeySDKTests/BITAuthenticatorTests.m | 25 +++++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/Classes/BITAuthenticator.h b/Classes/BITAuthenticator.h index 29aad96fd4..fd4158d6d7 100644 --- a/Classes/BITAuthenticator.h +++ b/Classes/BITAuthenticator.h @@ -81,10 +81,11 @@ typedef void(^tValidationCompletion)(BOOL validated, NSError *error); * to provide better error reporting & analytics. If authenticator is configured to login * (@see BITAuthenticatorValidationType), this identifier is retrieved from HockeyApp. In case * it is disabled, it returns the vendorIdentifier provided by UIKit. + * KVO'able * * @return a string identifying this app installation */ -- (NSString *) installationIdentification; +@property (nonatomic, readonly) NSString *installationIdentification; #pragma mark - Authentication /** diff --git a/Classes/BITAuthenticator.m b/Classes/BITAuthenticator.m index f5378ee7cc..363b799902 100644 --- a/Classes/BITAuthenticator.m +++ b/Classes/BITAuthenticator.m @@ -328,11 +328,13 @@ static NSString* const kBITAuthenticatorLastAuthenticatedVersionKey = @"BITAuthe #pragma mark - Property overrides - (void)setAuthenticationToken:(NSString *)authenticationToken { if(![self.authenticationToken isEqualToString:authenticationToken]) { + [self willChangeValueForKey:@"installationIdentification"]; if(nil == authenticationToken) { [self removeKeyFromKeychain:kBITAuthenticatorAuthTokenKey]; } else { [self addStringValueToKeychain:authenticationToken forKey:kBITAuthenticatorAuthTokenKey]; } + [self didChangeValueForKey:@"installationIdentification"]; } } diff --git a/Support/HockeySDKTests/BITAuthenticatorTests.m b/Support/HockeySDKTests/BITAuthenticatorTests.m index 9ded1ce2bc..1486c0c619 100644 --- a/Support/HockeySDKTests/BITAuthenticatorTests.m +++ b/Support/HockeySDKTests/BITAuthenticatorTests.m @@ -27,11 +27,14 @@ - (NSString*) uniqueIdentifier {return @"reallyUnique";} @end +static void *kInstallationIdentification = &kInstallationIdentification; + @interface BITAuthenticatorTests : SenTestCase @end @implementation BITAuthenticatorTests { BITAuthenticator *_sut; + BOOL _KVOCalled; } - (void)setUp { @@ -190,6 +193,28 @@ assertThat(_sut.authenticationToken, equalTo(nil)); } +- (void) testThatKVOWorksOnApplicationIdentification { + //this will prepare everything and show the viewcontroller + [_sut authenticateWithCompletion:nil]; + + [_sut addObserver:self forKeyPath:@"installationIdentification" + options:0 + context:kInstallationIdentification]; + + //fake delegate call from the viewcontroller + [_sut authenticationViewControllerDidCancel:nil]; + assertThatBool(_KVOCalled, equalToBool(YES)); + [_sut removeObserver:self forKeyPath:@"installationIdentification"]; +} + +- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { + if(kInstallationIdentification == context) { + _KVOCalled = YES; + } else { + [super observeValueForKeyPath:keyPath ofObject:object change:change context:context]; + } +} + #pragma mark - validation tests - (void) testThatValidationWithoutTokenWantsToShowTheAuthenticationViewController { id delegateMock = mockProtocol(@protocol(BITAuthenticatorDelegate));