mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-07-31 23:47:01 +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
|
* to provide better error reporting & analytics. If authenticator is configured to login
|
||||||
* (@see BITAuthenticatorValidationType), this identifier is retrieved from HockeyApp. In case
|
* (@see BITAuthenticatorValidationType), this identifier is retrieved from HockeyApp. In case
|
||||||
* it is disabled, it returns the vendorIdentifier provided by UIKit.
|
* it is disabled, it returns the vendorIdentifier provided by UIKit.
|
||||||
|
* KVO'able
|
||||||
*
|
*
|
||||||
* @return a string identifying this app installation
|
* @return a string identifying this app installation
|
||||||
*/
|
*/
|
||||||
- (NSString *) installationIdentification;
|
@property (nonatomic, readonly) NSString *installationIdentification;
|
||||||
|
|
||||||
#pragma mark - Authentication
|
#pragma mark - Authentication
|
||||||
/**
|
/**
|
||||||
|
@ -328,11 +328,13 @@ static NSString* const kBITAuthenticatorLastAuthenticatedVersionKey = @"BITAuthe
|
|||||||
#pragma mark - Property overrides
|
#pragma mark - Property overrides
|
||||||
- (void)setAuthenticationToken:(NSString *)authenticationToken {
|
- (void)setAuthenticationToken:(NSString *)authenticationToken {
|
||||||
if(![self.authenticationToken isEqualToString:authenticationToken]) {
|
if(![self.authenticationToken isEqualToString:authenticationToken]) {
|
||||||
|
[self willChangeValueForKey:@"installationIdentification"];
|
||||||
if(nil == authenticationToken) {
|
if(nil == authenticationToken) {
|
||||||
[self removeKeyFromKeychain:kBITAuthenticatorAuthTokenKey];
|
[self removeKeyFromKeychain:kBITAuthenticatorAuthTokenKey];
|
||||||
} else {
|
} else {
|
||||||
[self addStringValueToKeychain:authenticationToken forKey:kBITAuthenticatorAuthTokenKey];
|
[self addStringValueToKeychain:authenticationToken forKey:kBITAuthenticatorAuthTokenKey];
|
||||||
}
|
}
|
||||||
|
[self didChangeValueForKey:@"installationIdentification"];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,11 +27,14 @@
|
|||||||
- (NSString*) uniqueIdentifier {return @"reallyUnique";}
|
- (NSString*) uniqueIdentifier {return @"reallyUnique";}
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
static void *kInstallationIdentification = &kInstallationIdentification;
|
||||||
|
|
||||||
@interface BITAuthenticatorTests : SenTestCase
|
@interface BITAuthenticatorTests : SenTestCase
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation BITAuthenticatorTests {
|
@implementation BITAuthenticatorTests {
|
||||||
BITAuthenticator *_sut;
|
BITAuthenticator *_sut;
|
||||||
|
BOOL _KVOCalled;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setUp {
|
- (void)setUp {
|
||||||
@ -190,6 +193,28 @@
|
|||||||
assertThat(_sut.authenticationToken, equalTo(nil));
|
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
|
#pragma mark - validation tests
|
||||||
- (void) testThatValidationWithoutTokenWantsToShowTheAuthenticationViewController {
|
- (void) testThatValidationWithoutTokenWantsToShowTheAuthenticationViewController {
|
||||||
id delegateMock = mockProtocol(@protocol(BITAuthenticatorDelegate));
|
id delegateMock = mockProtocol(@protocol(BITAuthenticatorDelegate));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user