Skip to content

Commit

Permalink
Updated to no longer save custom URL
Browse files Browse the repository at this point in the history
  • Loading branch information
nsingh-branch committed Feb 14, 2024
1 parent 2481367 commit 9a0722e
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 66 deletions.
28 changes: 0 additions & 28 deletions Branch-TestBed/Branch-SDK-Tests/BNCPreferenceHelperTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -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/";
Expand Down
2 changes: 1 addition & 1 deletion Branch-TestBed/Branch-TestBed/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 0 additions & 2 deletions BranchSDK/BNCPreferenceHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
29 changes: 0 additions & 29 deletions BranchSDK/BNCPreferenceHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -68,7 +67,6 @@ @interface BNCPreferenceHelper () {
NSOperationQueue *_persistPrefsQueue;
NSString *_lastSystemBuildVersion;
NSString *_browserUserAgentString;
NSString *_branchAPIURL;
NSString *_referringURL;
}

Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions BranchSDK/BNCServerAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 7 additions & 3 deletions BranchSDK/BNCServerAPI.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ - (instancetype)init {
self.useTrackingDomain = NO;
self.useEUServers = NO;
self.automaticallyEnableTrackingDomain = YES;
self.customAPIURL = NULL;
}
return self;
}
Expand Down Expand Up @@ -78,6 +79,10 @@ - (BOOL)optedIntoIDFA {

// Linking endpoints are not used for Ads tracking
- (NSString *)getBaseURLForLinkingEndpoints {
if (self.customAPIURL) {
return self.customAPIURL;

Check warning on line 83 in BranchSDK/BNCServerAPI.m

View check run for this annotation

Codecov / codecov/patch

BranchSDK/BNCServerAPI.m#L83

Added line #L83 was not covered by tests
}

NSString * urlString;
if (self.useEUServers){
urlString = BNC_EU_API_URL;
Expand All @@ -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;

Check warning on line 99 in BranchSDK/BNCServerAPI.m

View check run for this annotation

Codecov / codecov/patch

BranchSDK/BNCServerAPI.m#L99

Added line #L99 was not covered by tests
}

if (self.automaticallyEnableTrackingDomain) {
Expand Down
2 changes: 1 addition & 1 deletion BranchSDK/Branch.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 6 additions & 2 deletions BranchSDK/Branch.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Check warning on line 431 in BranchSDK/Branch.m

View check run for this annotation

Codecov / codecov/patch

BranchSDK/Branch.m#L431

Added line #L431 was not covered by tests
} else {
BNCLogWarning(@"Ignoring invalid custom API URL");
}
}

Check warning on line 435 in BranchSDK/Branch.m

View check run for this annotation

Codecov / codecov/patch

BranchSDK/Branch.m#L434-L435

Added lines #L434 - L435 were not covered by tests

- (void)setDebug {
Expand Down

0 comments on commit 9a0722e

Please sign in to comment.