Skip to content

Commit 9a0722e

Browse files
committed
Updated to no longer save custom URL
1 parent 2481367 commit 9a0722e

File tree

8 files changed

+17
-66
lines changed

8 files changed

+17
-66
lines changed

Branch-TestBed/Branch-SDK-Tests/BNCPreferenceHelperTests.m

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -199,34 +199,6 @@ - (void)testURLSkipList {
199199
XCTAssert([filterDesc isEqualToString:valueDesc]);
200200
}
201201

202-
- (void)testSetAPIURL_Example {
203-
204-
NSString *url = @"https://www.example.com/";
205-
[self.prefHelper setBranchAPIURL:url] ;
206-
207-
NSString *urlStored = self.prefHelper.branchAPIURL ;
208-
XCTAssert([url isEqualToString:urlStored]);
209-
}
210-
211-
- (void)testSetAPIURL_InvalidHttp {
212-
213-
NSString *url = @"Invalid://www.example.com/";
214-
[self.prefHelper setBranchAPIURL:url] ;
215-
216-
NSString *urlStored = self.prefHelper.branchAPIURL ;
217-
XCTAssert(![url isEqualToString:urlStored]);
218-
XCTAssert([urlStored isEqualToString:BNC_API_URL]);
219-
}
220-
221-
- (void)testSetAPIURL_InvalidEmpty {
222-
223-
[self.prefHelper setBranchAPIURL:@""] ;
224-
225-
NSString *urlStored = self.prefHelper.branchAPIURL ;
226-
XCTAssert(![urlStored isEqualToString:@""]);
227-
XCTAssert([urlStored isEqualToString:BNC_API_URL]);
228-
}
229-
230202
- (void)testSetCDNBaseURL_Example {
231203

232204
NSString *url = @"https://www.example.com/";

Branch-TestBed/Branch-TestBed/AppDelegate.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ - (BOOL)application:(UIApplication *)application
3636
Branch *branch = [Branch getInstance];
3737

3838
// Change the Branch base API URL
39-
//[branch setAPIUrl:@"https://api3.branch.io"];
39+
//[Branch setAPIUrl:@"https://api3.branch.io"];
4040

4141
// test pre init support
4242
//[self testDispatchToIsolationQueue:branch]

BranchSDK/BNCPreferenceHelper.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ NSURL* /* _Nonnull */ BNCURLForBranchDirectory(void);
5151
@property (copy, nonatomic) NSString *lastSystemBuildVersion;
5252
@property (copy, nonatomic) NSString *browserUserAgentString;
5353
@property (copy, nonatomic) NSString *referringURL;
54-
@property (copy, nonatomic) NSString *branchAPIURL;
5554
@property (assign, nonatomic) BOOL limitFacebookTracking;
5655
@property (strong, nonatomic) NSDate *previousAppBuildDate;
5756
@property (assign, nonatomic, readwrite) BOOL disableAdNetworkCallouts;
@@ -77,7 +76,6 @@ NSURL* /* _Nonnull */ BNCURLForBranchDirectory(void);
7776

7877
+ (BNCPreferenceHelper *)sharedInstance;
7978

80-
- (void)setBranchAPIURL:(NSString *)url;
8179
- (void)setPatternListURL:(NSString *)url;
8280

8381
- (void)setRequestMetadataKey:(NSString *)key value:(NSObject *)value;

BranchSDK/BNCPreferenceHelper.m

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
static NSString * const BRANCH_PREFS_KEY_LAST_RUN_BRANCH_KEY = @"bnc_last_run_branch_key";
2727
static NSString * const BRANCH_PREFS_KEY_LAST_STRONG_MATCH_DATE = @"bnc_strong_match_created_date";
2828

29-
static NSString * const BRANCH_PREFS_KEY_CUSTOM_API_URL = @"bnc_custom_api_url";
3029
static NSString * const BRANCH_PREFS_KEY_PATTERN_LIST_URL = @"bnc_pattern_list_url";
3130

3231
static NSString * const BRANCH_PREFS_KEY_RANDOMIZED_DEVICE_TOKEN = @"bnc_randomized_device_token";
@@ -68,7 +67,6 @@ @interface BNCPreferenceHelper () {
6867
NSOperationQueue *_persistPrefsQueue;
6968
NSString *_lastSystemBuildVersion;
7069
NSString *_browserUserAgentString;
71-
NSString *_branchAPIURL;
7270
NSString *_referringURL;
7371
}
7472

@@ -156,33 +154,6 @@ - (void) dealloc {
156154

157155
#pragma mark - API methods
158156

159-
- (void)setBranchAPIURL:(NSString *)url {
160-
if ([url hasPrefix:@"http://"] || [url hasPrefix:@"https://"] ){
161-
@synchronized (self) {
162-
_branchAPIURL = [url copy];
163-
[self writeObjectToDefaults:BRANCH_PREFS_KEY_CUSTOM_API_URL value:_branchAPIURL];
164-
}
165-
} else {
166-
BNCLogWarning(@"Ignoring invalid custom API URL");
167-
}
168-
}
169-
170-
- (NSString *)branchAPIURL {
171-
@synchronized (self) {
172-
if (!_branchAPIURL) {
173-
_branchAPIURL = [self readStringFromDefaults:BRANCH_PREFS_KEY_CUSTOM_API_URL];
174-
}
175-
176-
// return the default URL in the event there's nothing in storage
177-
if (_branchAPIURL == nil || [_branchAPIURL isEqualToString:@""]) {
178-
_branchAPIURL = [BNC_API_URL copy];
179-
[self writeObjectToDefaults:BRANCH_PREFS_KEY_CUSTOM_API_URL value:_branchAPIURL];
180-
}
181-
182-
return _branchAPIURL;
183-
}
184-
}
185-
186157
- (void)setPatternListURL:(NSString *)url {
187158
if ([url hasPrefix:@"http://"] || [url hasPrefix:@"https://"] ){
188159
@synchronized (self) {

BranchSDK/BNCServerAPI.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ NS_ASSUME_NONNULL_BEGIN
3333
// Used to enable unit tests without regard for ATT authorization status
3434
@property (nonatomic, assign, readwrite) BOOL automaticallyEnableTrackingDomain;
3535

36+
@property (nonatomic, copy, readwrite, nullable) NSString *customAPIURL;
37+
3638
@end
3739

3840
NS_ASSUME_NONNULL_END

BranchSDK/BNCServerAPI.m

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ - (instancetype)init {
3030
self.useTrackingDomain = NO;
3131
self.useEUServers = NO;
3232
self.automaticallyEnableTrackingDomain = YES;
33+
self.customAPIURL = NULL;
3334
}
3435
return self;
3536
}
@@ -78,6 +79,10 @@ - (BOOL)optedIntoIDFA {
7879

7980
// Linking endpoints are not used for Ads tracking
8081
- (NSString *)getBaseURLForLinkingEndpoints {
82+
if (self.customAPIURL) {
83+
return self.customAPIURL;
84+
}
85+
8186
NSString * urlString;
8287
if (self.useEUServers){
8388
urlString = BNC_EU_API_URL;
@@ -90,9 +95,8 @@ - (NSString *)getBaseURLForLinkingEndpoints {
9095

9196
- (NSString *)getBaseURL {
9297
//Check if user has set a custom API base URL
93-
NSString *url = [[BNCPreferenceHelper sharedInstance] branchAPIURL];
94-
if (url && ![url isEqualToString:BNC_API_URL]) {
95-
return url;
98+
if (self.customAPIURL) {
99+
return self.customAPIURL;
96100
}
97101

98102
if (self.automaticallyEnableTrackingDomain) {

BranchSDK/Branch.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ extern NSString * __nonnull const BNCSpotlightFeature;
579579
Sets a custom base URL for all calls to the Branch API.
580580
@param url Base URL that the Branch API will use.
581581
*/
582-
- (void)setAPIUrl:(NSString *)url;
582+
+ (void)setAPIUrl:(NSString *)url;
583583

584584
/**
585585
setDebug is deprecated and all functionality has been disabled.

BranchSDK/Branch.m

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -426,8 +426,12 @@ - (void)useEUEndpoints {
426426
[BNCServerAPI sharedInstance].useEUServers = YES;
427427
}
428428

429-
- (void)setAPIUrl:(NSString *)url {
430-
[[BNCPreferenceHelper sharedInstance] setBranchAPIURL:url];
429+
+ (void)setAPIUrl:(NSString *)url {
430+
if ([url hasPrefix:@"http://"] || [url hasPrefix:@"https://"] ){
431+
[BNCServerAPI sharedInstance].customAPIURL = url;
432+
} else {
433+
BNCLogWarning(@"Ignoring invalid custom API URL");
434+
}
431435
}
432436

433437
- (void)setDebug {

0 commit comments

Comments
 (0)