Skip to content

Commit 2a1c0c2

Browse files
authored
Merge pull request #396 from BranchMetrics/white-listed-schemes
White listed schemes
2 parents 6a7ed08 + f199012 commit 2a1c0c2

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

Branch-SDK/Branch-SDK/Branch.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,19 @@ typedef NS_ENUM(NSUInteger, BranchCreditHistoryOrder) {
357357
*/
358358
-(void)setDeepLinkDebugMode:(NSDictionary *)debugParams;
359359

360+
/**
361+
Add a scheme to a whitelist of URI schemes that will be tracked by Branch. Default to all schemes.
362+
363+
@param the scheme to add to the whitelist, i.e. @"http", @"https" or @"myapp"
364+
*/
365+
-(void)addWhiteListedScheme:(NSString *)scheme;
366+
367+
/**
368+
Add an array of schemes to a whitelist of URI schemes that will be tracked by Branch. Default to all schemes.
369+
370+
@param the array of schemes to add to the whitelist, i.e. @[@"http", @"https", @"myapp"]
371+
*/
372+
-(void)setWhiteListedSchemes:(NSArray *)schemes;
360373

361374
/**
362375
Register your Facebook SDK's FBSDKAppLinkUtility class to be used by Branch for deferred deep linking from their platform

Branch-SDK/Branch-SDK/Branch.m

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ @interface Branch() <BranchDeepLinkingControllerCompletionDelegate, FABKit>
8080
@property (strong, nonatomic) NSDictionary *deepLinkDebugParams;
8181
@property (assign, nonatomic) BOOL accountForFacebookSDK;
8282
@property (assign, nonatomic) id FBSDKAppLinkUtility;
83+
@property (strong, nonatomic) NSMutableArray *whiteListedSchemeList;
8384

8485
@end
8586

@@ -147,6 +148,7 @@ - (id)initWithInterface:(BNCServerInterface *)interface queue:(BNCServerRequestQ
147148
_processing_sema = dispatch_semaphore_create(1);
148149
_networkCount = 0;
149150
_deepLinkControllers = [[NSMutableDictionary alloc] init];
151+
_whiteListedSchemeList = [[NSMutableArray alloc] init];
150152
_useCookieBasedMatching = YES;
151153

152154
NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
@@ -320,12 +322,29 @@ - (void) setDeepLinkDebugMode:(NSDictionary *)debugParams {
320322
self.deepLinkDebugParams = debugParams;
321323
}
322324

325+
-(void)setWhiteListedSchemes:(NSArray *)schemes {
326+
self.whiteListedSchemeList = [schemes mutableCopy];
327+
}
328+
329+
-(void)addWhiteListedScheme:(NSString *)scheme {
330+
[self.whiteListedSchemeList addObject:scheme];
331+
}
323332

324333
- (BOOL)handleDeepLink:(NSURL *)url {
325334
BOOL handled = NO;
326335
if (url && ![url isEqual:[NSNull null]]) {
327-
//always save the incoming url in the preferenceHelper in the externalIntentURI field
328-
self.preferenceHelper.externalIntentURI = [url absoluteString];
336+
337+
// save the incoming url in the preferenceHelper in the externalIntentURI field
338+
if ([self.whiteListedSchemeList count]) {
339+
for (NSString *scheme in self.whiteListedSchemeList) {
340+
if ([scheme isEqualToString:[url scheme]]) {
341+
self.preferenceHelper.externalIntentURI = [url absoluteString];
342+
break;
343+
}
344+
}
345+
} else {
346+
self.preferenceHelper.externalIntentURI = [url absoluteString];
347+
}
329348

330349
NSString *query = [url fragment];
331350
if (!query) {

Branch-TestBed/Branch-TestBed/AppDelegate.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
2121

2222
Branch *branch = [Branch getInstance];
2323
[branch setDebug];
24+
[branch setWhiteListedSchemes:@[@"branchtest"]];
2425

2526
// Automatic Deeplinking on "deeplink_text"
2627
NavigationController *navigationController = [[UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]] instantiateInitialViewController];

0 commit comments

Comments
 (0)