mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-07-31 07:30:40 +00:00
make installationIdentification KVO'able
This commit is contained in:
parent
96304ac639
commit
6f64b8e5d6
@ -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
|
||||
/**
|
||||
|
@ -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"];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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));
|
||||
|
Loading…
x
Reference in New Issue
Block a user