diff --git a/Branch-TestBed/Branch-SDK-Tests/BNCPreferenceHelperTests.m b/Branch-TestBed/Branch-SDK-Tests/BNCPreferenceHelperTests.m index 249fbe2de..5269501b3 100644 --- a/Branch-TestBed/Branch-SDK-Tests/BNCPreferenceHelperTests.m +++ b/Branch-TestBed/Branch-SDK-Tests/BNCPreferenceHelperTests.m @@ -199,34 +199,6 @@ - (void)testURLSkipList { XCTAssert([filterDesc isEqualToString:valueDesc]); } -- (void)testSetAPIURL_Example { - - NSString *url = @"https://www.example.com/"; - [self.prefHelper setBranchAPIURL:url] ; - - NSString *urlStored = self.prefHelper.branchAPIURL ; - XCTAssert([url isEqualToString:urlStored]); -} - -- (void)testSetAPIURL_InvalidHttp { - - NSString *url = @"Invalid://www.example.com/"; - [self.prefHelper setBranchAPIURL:url] ; - - NSString *urlStored = self.prefHelper.branchAPIURL ; - XCTAssert(![url isEqualToString:urlStored]); - XCTAssert([urlStored isEqualToString:BNC_API_URL]); -} - -- (void)testSetAPIURL_InvalidEmpty { - - [self.prefHelper setBranchAPIURL:@""] ; - - NSString *urlStored = self.prefHelper.branchAPIURL ; - XCTAssert(![urlStored isEqualToString:@""]); - XCTAssert([urlStored isEqualToString:BNC_API_URL]); -} - - (void)testSetCDNBaseURL_Example { NSString *url = @"https://www.example.com/"; diff --git a/Branch-TestBed/Branch-TestBed/AppDelegate.m b/Branch-TestBed/Branch-TestBed/AppDelegate.m index d59683f7d..d02c3a6cd 100644 --- a/Branch-TestBed/Branch-TestBed/AppDelegate.m +++ b/Branch-TestBed/Branch-TestBed/AppDelegate.m @@ -36,7 +36,7 @@ - (BOOL)application:(UIApplication *)application Branch *branch = [Branch getInstance]; // Change the Branch base API URL - //[branch setAPIUrl:@"https://api3.branch.io"]; + //[Branch setAPIUrl:@"https://api3.branch.io"]; // test pre init support //[self testDispatchToIsolationQueue:branch] diff --git a/BranchSDK/BNCPreferenceHelper.h b/BranchSDK/BNCPreferenceHelper.h index d7f56047b..336012609 100644 --- a/BranchSDK/BNCPreferenceHelper.h +++ b/BranchSDK/BNCPreferenceHelper.h @@ -51,7 +51,6 @@ NSURL* /* _Nonnull */ BNCURLForBranchDirectory(void); @property (copy, nonatomic) NSString *lastSystemBuildVersion; @property (copy, nonatomic) NSString *browserUserAgentString; @property (copy, nonatomic) NSString *referringURL; -@property (copy, nonatomic) NSString *branchAPIURL; @property (assign, nonatomic) BOOL limitFacebookTracking; @property (strong, nonatomic) NSDate *previousAppBuildDate; @property (assign, nonatomic, readwrite) BOOL disableAdNetworkCallouts; @@ -77,7 +76,6 @@ NSURL* /* _Nonnull */ BNCURLForBranchDirectory(void); + (BNCPreferenceHelper *)sharedInstance; -- (void)setBranchAPIURL:(NSString *)url; - (void)setPatternListURL:(NSString *)url; - (void)setRequestMetadataKey:(NSString *)key value:(NSObject *)value; diff --git a/BranchSDK/BNCPreferenceHelper.m b/BranchSDK/BNCPreferenceHelper.m index dfb9e27cd..486df900a 100644 --- a/BranchSDK/BNCPreferenceHelper.m +++ b/BranchSDK/BNCPreferenceHelper.m @@ -26,7 +26,6 @@ static NSString * const BRANCH_PREFS_KEY_LAST_RUN_BRANCH_KEY = @"bnc_last_run_branch_key"; static NSString * const BRANCH_PREFS_KEY_LAST_STRONG_MATCH_DATE = @"bnc_strong_match_created_date"; -static NSString * const BRANCH_PREFS_KEY_CUSTOM_API_URL = @"bnc_custom_api_url"; static NSString * const BRANCH_PREFS_KEY_PATTERN_LIST_URL = @"bnc_pattern_list_url"; static NSString * const BRANCH_PREFS_KEY_RANDOMIZED_DEVICE_TOKEN = @"bnc_randomized_device_token"; @@ -68,7 +67,6 @@ @interface BNCPreferenceHelper () { NSOperationQueue *_persistPrefsQueue; NSString *_lastSystemBuildVersion; NSString *_browserUserAgentString; - NSString *_branchAPIURL; NSString *_referringURL; } @@ -156,33 +154,6 @@ - (void) dealloc { #pragma mark - API methods -- (void)setBranchAPIURL:(NSString *)url { - if ([url hasPrefix:@"http://"] || [url hasPrefix:@"https://"] ){ - @synchronized (self) { - _branchAPIURL = [url copy]; - [self writeObjectToDefaults:BRANCH_PREFS_KEY_CUSTOM_API_URL value:_branchAPIURL]; - } - } else { - BNCLogWarning(@"Ignoring invalid custom API URL"); - } -} - -- (NSString *)branchAPIURL { - @synchronized (self) { - if (!_branchAPIURL) { - _branchAPIURL = [self readStringFromDefaults:BRANCH_PREFS_KEY_CUSTOM_API_URL]; - } - - // return the default URL in the event there's nothing in storage - if (_branchAPIURL == nil || [_branchAPIURL isEqualToString:@""]) { - _branchAPIURL = [BNC_API_URL copy]; - [self writeObjectToDefaults:BRANCH_PREFS_KEY_CUSTOM_API_URL value:_branchAPIURL]; - } - - return _branchAPIURL; - } -} - - (void)setPatternListURL:(NSString *)url { if ([url hasPrefix:@"http://"] || [url hasPrefix:@"https://"] ){ @synchronized (self) { diff --git a/BranchSDK/BNCServerAPI.h b/BranchSDK/BNCServerAPI.h index 6fc218e65..c44c80577 100644 --- a/BranchSDK/BNCServerAPI.h +++ b/BranchSDK/BNCServerAPI.h @@ -33,6 +33,8 @@ NS_ASSUME_NONNULL_BEGIN // Used to enable unit tests without regard for ATT authorization status @property (nonatomic, assign, readwrite) BOOL automaticallyEnableTrackingDomain; +@property (nonatomic, copy, readwrite, nullable) NSString *customAPIURL; + @end NS_ASSUME_NONNULL_END diff --git a/BranchSDK/BNCServerAPI.m b/BranchSDK/BNCServerAPI.m index 6c7900911..7d7e33768 100644 --- a/BranchSDK/BNCServerAPI.m +++ b/BranchSDK/BNCServerAPI.m @@ -30,6 +30,7 @@ - (instancetype)init { self.useTrackingDomain = NO; self.useEUServers = NO; self.automaticallyEnableTrackingDomain = YES; + self.customAPIURL = NULL; } return self; } @@ -78,6 +79,10 @@ - (BOOL)optedIntoIDFA { // Linking endpoints are not used for Ads tracking - (NSString *)getBaseURLForLinkingEndpoints { + if (self.customAPIURL) { + return self.customAPIURL; + } + NSString * urlString; if (self.useEUServers){ urlString = BNC_EU_API_URL; @@ -90,9 +95,8 @@ - (NSString *)getBaseURLForLinkingEndpoints { - (NSString *)getBaseURL { //Check if user has set a custom API base URL - NSString *url = [[BNCPreferenceHelper sharedInstance] branchAPIURL]; - if (url && ![url isEqualToString:BNC_API_URL]) { - return url; + if (self.customAPIURL) { + return self.customAPIURL; } if (self.automaticallyEnableTrackingDomain) { diff --git a/BranchSDK/Branch.h b/BranchSDK/Branch.h index f3701460d..134877928 100644 --- a/BranchSDK/Branch.h +++ b/BranchSDK/Branch.h @@ -579,7 +579,7 @@ extern NSString * __nonnull const BNCSpotlightFeature; Sets a custom base URL for all calls to the Branch API. @param url Base URL that the Branch API will use. */ -- (void)setAPIUrl:(NSString *)url; ++ (void)setAPIUrl:(NSString *)url; /** setDebug is deprecated and all functionality has been disabled. diff --git a/BranchSDK/Branch.m b/BranchSDK/Branch.m index 1d2254a75..feece0a22 100644 --- a/BranchSDK/Branch.m +++ b/BranchSDK/Branch.m @@ -426,8 +426,12 @@ - (void)useEUEndpoints { [BNCServerAPI sharedInstance].useEUServers = YES; } -- (void)setAPIUrl:(NSString *)url { - [[BNCPreferenceHelper sharedInstance] setBranchAPIURL:url]; ++ (void)setAPIUrl:(NSString *)url { + if ([url hasPrefix:@"http://"] || [url hasPrefix:@"https://"] ){ + [BNCServerAPI sharedInstance].customAPIURL = url; + } else { + BNCLogWarning(@"Ignoring invalid custom API URL"); + } } - (void)setDebug {