diff --git a/Branch-TestBed/Branch-TestBed/AppDelegate.m b/Branch-TestBed/Branch-TestBed/AppDelegate.m index 09925169f..d59683f7d 100644 --- a/Branch-TestBed/Branch-TestBed/AppDelegate.m +++ b/Branch-TestBed/Branch-TestBed/AppDelegate.m @@ -34,7 +34,10 @@ - (BOOL)application:(UIApplication *)application // Branch.useTestBranchKey = YES; // Make sure to comment this line out for production apps!!! Branch *branch = [Branch getInstance]; - + + // Change the Branch base API URL + //[branch setAPIUrl:@"https://api3.branch.io"]; + // test pre init support //[self testDispatchToIsolationQueue:branch] diff --git a/BranchSDK/BNCPreferenceHelper.m b/BranchSDK/BNCPreferenceHelper.m index fb7a3ca58..dfb9e27cd 100644 --- a/BranchSDK/BNCPreferenceHelper.m +++ b/BranchSDK/BNCPreferenceHelper.m @@ -26,7 +26,7 @@ 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_API_URL = @"bnc_api_url"; +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"; @@ -160,24 +160,23 @@ - (void)setBranchAPIURL:(NSString *)url { if ([url hasPrefix:@"http://"] || [url hasPrefix:@"https://"] ){ @synchronized (self) { _branchAPIURL = [url copy]; - [self writeObjectToDefaults:BRANCH_PREFS_KEY_API_URL value:_branchAPIURL]; + [self writeObjectToDefaults:BRANCH_PREFS_KEY_CUSTOM_API_URL value:_branchAPIURL]; } } else { BNCLogWarning(@"Ignoring invalid custom API URL"); } } -// TODO: This method is not used with the Tracking domain change. See SDK-2118 - (NSString *)branchAPIURL { @synchronized (self) { if (!_branchAPIURL) { - _branchAPIURL = [self readStringFromDefaults:BRANCH_PREFS_KEY_API_URL]; + _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_API_URL value:_branchAPIURL]; + [self writeObjectToDefaults:BRANCH_PREFS_KEY_CUSTOM_API_URL value:_branchAPIURL]; } return _branchAPIURL; diff --git a/BranchSDK/BNCServerAPI.m b/BranchSDK/BNCServerAPI.m index 2e9bc5c2a..6c7900911 100644 --- a/BranchSDK/BNCServerAPI.m +++ b/BranchSDK/BNCServerAPI.m @@ -9,6 +9,7 @@ #import "BNCSystemObserver.h" #import "BNCConfig.h" #import "BranchConstants.h" +#import "BNCPreferenceHelper.h" @implementation BNCServerAPI @@ -88,6 +89,12 @@ - (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.automaticallyEnableTrackingDomain) { self.useTrackingDomain = [self optedIntoIDFA]; } diff --git a/BranchSDK/Branch.h b/BranchSDK/Branch.h index d4ab71e10..f3701460d 100644 --- a/BranchSDK/Branch.h +++ b/BranchSDK/Branch.h @@ -575,6 +575,12 @@ extern NSString * __nonnull const BNCSpotlightFeature; */ - (void)useEUEndpoints; +/** +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; + /** setDebug is deprecated and all functionality has been disabled. diff --git a/BranchSDK/Branch.m b/BranchSDK/Branch.m index da80d47ee..1d2254a75 100644 --- a/BranchSDK/Branch.m +++ b/BranchSDK/Branch.m @@ -426,6 +426,10 @@ - (void)useEUEndpoints { [BNCServerAPI sharedInstance].useEUServers = YES; } +- (void)setAPIUrl:(NSString *)url { + [[BNCPreferenceHelper sharedInstance] setBranchAPIURL:url]; +} + - (void)setDebug { NSLog(@"Branch setDebug is deprecated and all functionality has been disabled. " "If you wish to enable logging, please invoke enableLogging. " diff --git a/BranchSDK/BranchPluginSupport.m b/BranchSDK/BranchPluginSupport.m index ca07797ed..e577337b3 100644 --- a/BranchSDK/BranchPluginSupport.m +++ b/BranchSDK/BranchPluginSupport.m @@ -54,7 +54,6 @@ + (BranchPluginSupport *)instance { #pragma mark - Server URL methods -// With the change to support Apple's tracking domain feature, this API no longer works. See SDK-2118 // Overrides base API URL + (void)setAPIUrl:(NSString *)url { [[BNCPreferenceHelper sharedInstance] setBranchAPIURL:url];