Skip to content

Commit

Permalink
Added method to set API URL
Browse files Browse the repository at this point in the history
  • Loading branch information
nsingh-branch committed Feb 13, 2024
1 parent 18cc5aa commit 6bc64c8
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 7 deletions.
5 changes: 4 additions & 1 deletion Branch-TestBed/Branch-TestBed/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
9 changes: 4 additions & 5 deletions BranchSDK/BNCPreferenceHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions BranchSDK/BNCServerAPI.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#import "BNCSystemObserver.h"
#import "BNCConfig.h"
#import "BranchConstants.h"
#import "BNCPreferenceHelper.h"

@implementation BNCServerAPI

Expand Down Expand Up @@ -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;

Check warning on line 95 in BranchSDK/BNCServerAPI.m

View check run for this annotation

Codecov / codecov/patch

BranchSDK/BNCServerAPI.m#L95

Added line #L95 was not covered by tests
}

if (self.automaticallyEnableTrackingDomain) {
self.useTrackingDomain = [self optedIntoIDFA];
}
Expand Down
6 changes: 6 additions & 0 deletions BranchSDK/Branch.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions BranchSDK/Branch.m
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,10 @@ - (void)useEUEndpoints {
[BNCServerAPI sharedInstance].useEUServers = YES;
}

- (void)setAPIUrl:(NSString *)url {
[[BNCPreferenceHelper sharedInstance] setBranchAPIURL:url];
}

Check warning on line 431 in BranchSDK/Branch.m

View check run for this annotation

Codecov / codecov/patch

BranchSDK/Branch.m#L430-L431

Added lines #L430 - L431 were not covered by tests

- (void)setDebug {
NSLog(@"Branch setDebug is deprecated and all functionality has been disabled. "
"If you wish to enable logging, please invoke enableLogging. "
Expand Down
1 change: 0 additions & 1 deletion BranchSDK/BranchPluginSupport.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down

0 comments on commit 6bc64c8

Please sign in to comment.