From 4b3c62040e9fa2dbb92ff39d06eadf68012ee652 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20Spie=C3=9F?= Date: Thu, 14 Apr 2016 00:45:38 +0200 Subject: [PATCH] Move client reconfiguration on serverURL change into BITCrashManager Having the different logics for retrieving an instance of `BITHockeyAppClient` on `BITHockeyManager` felt strange, therefore I decided to move the logic necessary when the serverURL of the `BITCrashManager` instance changes into the manager itself. --- Classes/BITCrashManager.m | 13 +++++++++++-- Classes/BITCrashManagerPrivate.h | 2 ++ Classes/BITHockeyManager.m | 12 +++--------- Support/HockeySDKTests/BITCrashManagerTests.m | 7 +------ 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/Classes/BITCrashManager.m b/Classes/BITCrashManager.m index 4516682c6e..6308fa5f11 100644 --- a/Classes/BITCrashManager.m +++ b/Classes/BITCrashManager.m @@ -200,12 +200,15 @@ static void uncaught_cxx_exception_handler(const BITCrashUncaughtCXXExceptionInf id _networkDidBecomeReachableObserver; } +@synthesize serverURL = _serverURL; -- (instancetype)init { - if ((self = [super init])) { +- (instancetype)initWithAppIdentifier:(NSString *)appIdentifier appEnvironment:(BITEnvironment)environment hockeyAppClient:(BITHockeyAppClient *)hockeyAppClient { + if ((self = [super initWithAppIdentifier:appIdentifier appEnvironment:environment])) { _delegate = nil; _isSetup = NO; + _hockeyAppClient = hockeyAppClient; + _showAlwaysButton = YES; _alertViewHandler = nil; @@ -264,6 +267,12 @@ static void uncaught_cxx_exception_handler(const BITCrashUncaughtCXXExceptionInf [[NSUserDefaults standardUserDefaults] setInteger:crashManagerStatus forKey:kBITCrashManagerStatus]; } +- (void)setServerURL:(NSString *)serverURL { + if ([serverURL isEqualToString:_serverURL]) { return; } + + _serverURL = serverURL; + self.hockeyAppClient = [[BITHockeyAppClient alloc] initWithBaseURL:[NSURL URLWithString:serverURL]]; +} #pragma mark - Private diff --git a/Classes/BITCrashManagerPrivate.h b/Classes/BITCrashManagerPrivate.h index 5bb40500e2..faf9f1ad14 100644 --- a/Classes/BITCrashManagerPrivate.h +++ b/Classes/BITCrashManagerPrivate.h @@ -83,6 +83,8 @@ #endif /* HOCKEYSDK_FEATURE_AUTHENTICATOR */ +- (instancetype)initWithAppIdentifier:(NSString *)appIdentifier appEnvironment:(BITEnvironment)environment hockeyAppClient:(BITHockeyAppClient *)hockeyAppClient NS_DESIGNATED_INITIALIZER; + - (void)cleanCrashReports; - (NSString *)userIDForCrashReport; diff --git a/Classes/BITHockeyManager.m b/Classes/BITHockeyManager.m index 0f7bec2002..78008705f9 100644 --- a/Classes/BITHockeyManager.m +++ b/Classes/BITHockeyManager.m @@ -241,7 +241,6 @@ bitstadium_info_t bitstadium_library_info __attribute__((section("__TEXT,__bit_h // start CrashManager if (![self isCrashManagerDisabled]) { BITHockeyLogDebug(@"INFO: Start CrashManager"); - [_crashManager setHockeyAppClient:[self hockeyAppClientWithServerURL:_crashManager.serverURL]]; #if HOCKEYSDK_FEATURE_AUTHENTICATOR if (_authenticator) { @@ -539,13 +538,6 @@ bitstadium_info_t bitstadium_library_info __attribute__((section("__TEXT,__bit_h return _hockeyAppClient; } -- (BITHockeyAppClient *)hockeyAppClientWithServerURL:(NSString *)serverURL { - if (!serverURL || [serverURL isEqualToString:self.serverURL]) { - return [self hockeyAppClient]; - } - return [[BITHockeyAppClient alloc] initWithBaseURL:[NSURL URLWithString:serverURL]]; -} - - (NSString *)integrationFlowTimeString { NSString *timeString = [[NSBundle mainBundle] objectForInfoDictionaryKey:BITHOCKEY_INTEGRATIONFLOW_TIMESTAMP]; @@ -693,7 +685,9 @@ bitstadium_info_t bitstadium_library_info __attribute__((section("__TEXT,__bit_h if (_validAppIdentifier) { #if HOCKEYSDK_FEATURE_CRASH_REPORTER BITHockeyLogDebug(@"INFO: Setup CrashManager"); - _crashManager = [[BITCrashManager alloc] initWithAppIdentifier:_appIdentifier appEnvironment:_appEnvironment]; + _crashManager = [[BITCrashManager alloc] initWithAppIdentifier:_appIdentifier + appEnvironment:_appEnvironment + hockeyAppClient:[self hockeyAppClient]]; _crashManager.delegate = _delegate; #endif /* HOCKEYSDK_FEATURE_CRASH_REPORTER */ diff --git a/Support/HockeySDKTests/BITCrashManagerTests.m b/Support/HockeySDKTests/BITCrashManagerTests.m index 92bdff300b..f3a995fc8a 100644 --- a/Support/HockeySDKTests/BITCrashManagerTests.m +++ b/Support/HockeySDKTests/BITCrashManagerTests.m @@ -40,12 +40,7 @@ static NSString *const kBITCrashMetaAttachment = @"BITCrashMetaAttachment"; [super setUp]; _startManagerInitialized = NO; - _sut = [[BITCrashManager alloc] initWithAppIdentifier:nil appEnvironment:BITEnvironmentOther]; - - _hockeyAppClient = [[BITHockeyAppClient alloc] initWithBaseURL:[NSURL URLWithString: BITHOCKEYSDK_URL]]; - _hockeyAppClient.baseURL = [NSURL URLWithString:BITHOCKEYSDK_URL]; - - [_sut setHockeyAppClient:_hockeyAppClient]; + _sut = [[BITCrashManager alloc] initWithAppIdentifier:nil appEnvironment:BITEnvironmentOther hockeyAppClient:[[BITHockeyAppClient alloc] initWithBaseURL:[NSURL URLWithString: BITHOCKEYSDK_URL]]]; } - (void)tearDown {