Skip to content

Commit dd9b058

Browse files
authored
Merge pull request #220 from BranchMetrics/openurl-method
Deprecated [RNBranch handleDeepLink:]
2 parents 7cfe06c + 84a130b commit dd9b058

File tree

6 files changed

+32
-29
lines changed

6 files changed

+32
-29
lines changed

examples/testbed_native_ios/testbed_native_ios/AppDelegate.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
2727
}
2828

2929
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
30-
if (![RNBranch handleDeepLink:url]) {
30+
if (![RNBranch.branch application:application openURL:url sourceApplication:sourceApplication annotation:annotation]) {
3131
// do other deep link routing for the Facebook SDK, Pinterest SDK, etc
3232
}
3333
return YES;

examples/testbed_simple/ios/testbed_simple/AppDelegate.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
4343
}
4444

4545
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
46-
if (![RNBranch handleDeepLink:url]) {
46+
if (![RNBranch.branch application:application openURL:url sourceApplication:sourceApplication annotation:annotation]) {
4747
// do other deep link routing for the Facebook SDK, Pinterest SDK, etc
4848
}
4949
return YES;

examples/webview_example/ios/webview_example/AppDelegate.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
4444

4545
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
4646
{
47-
return [RNBranch handleDeepLink:url] || [[UIApplication sharedApplication] openURL:url];
47+
return [RNBranch.branch application:app openURL:url options:options] || [[UIApplication sharedApplication] openURL:url];
4848
}
4949

5050
- (BOOL)application:(UIApplication *)app continueUserActivity:(nonnull NSUserActivity *)userActivity restorationHandler:(nonnull void (^)(NSArray * _Nullable))restorationHandler

examples/webview_example_native_ios/WebViewExample/AppDelegate.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
3737
}
3838

3939
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
40-
return RNBranch.handleDeepLink(url)
40+
return RNBranch.branch.application(app, open: url, options: options)
4141
}
4242

4343
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Void) -> Bool {

ios/RNBranch.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
#import <Foundation/Foundation.h>
22
#import <React/RCTBridgeModule.h>
33

4+
#import <Branch/Branch.h>
5+
46
extern NSString * _Nonnull const RNBranchLinkOpenedNotification;
57
extern NSString * _Nonnull const RNBranchLinkOpenedNotificationErrorKey;
68
extern NSString * _Nonnull const RNBranchLinkOpenedNotificationParamsKey;
79
extern NSString * _Nonnull const RNBranchLinkOpenedNotificationUriKey;
810
extern NSString * _Nonnull const RNBranchLinkOpenedNotificationBranchUniversalObjectKey;
911
extern NSString * _Nonnull const RNBranchLinkOpenedNotificationLinkPropertiesKey;
1012

11-
@class Branch;
1213

1314
@interface RNBranch : NSObject <RCTBridgeModule>
1415

16+
@property (class, readonly, nonnull) Branch *branch;
17+
1518
+ (void)initSessionWithLaunchOptions:(NSDictionary * _Nullable)launchOptions isReferrable:(BOOL)isReferrable;
16-
+ (BOOL)handleDeepLink:(NSURL * _Nonnull)url;
19+
+ (BOOL)handleDeepLink:(NSURL * _Nonnull)url __deprecated_msg("Please use [RNBranch.branch application:openURL:options] or [RNBranch.branch application:openURL:sourceApplication:annotation:] instead.");
1720
+ (BOOL)continueUserActivity:(NSUserActivity * _Nonnull)userActivity;
1821

1922
// Must be called before any other static method below
@@ -24,6 +27,4 @@ extern NSString * _Nonnull const RNBranchLinkOpenedNotificationLinkPropertiesKey
2427
+ (void)setAppleSearchAdsDebugMode;
2528
+ (void)setRequestMetadataKey:(NSString * _Nonnull)key value:(NSObject * _Nonnull)value;
2629

27-
+ (Branch * _Nonnull)branch;
28-
2930
@end

ios/RNBranch.m

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -41,27 +41,29 @@ @implementation RNBranch
4141

4242
+ (Branch *)branch
4343
{
44-
static Branch *instance;
45-
static dispatch_once_t once = 0;
46-
dispatch_once(&once, ^{
47-
RNBranchConfig *config = RNBranchConfig.instance;
48-
49-
// YES if either [RNBranch useTestInstance] was called or useTestInstance: true is present in branch.json.
50-
BOOL usingTestInstance = useTestInstance || config.useTestInstance;
51-
NSString *key = usingTestInstance ? config.testKey : config.liveKey;
52-
53-
if (key) {
54-
// Override the Info.plist if these are present.
55-
RCTLog(@"Using Branch key %@ from branch.json", key);
56-
instance = [Branch getInstance: key];
57-
}
58-
else {
59-
instance = usingTestInstance ? [Branch getTestInstance] : [Branch getInstance];
60-
}
61-
62-
[self setupBranchInstance:instance];
63-
});
64-
return instance;
44+
@synchronized(self.class) {
45+
static Branch *instance;
46+
static dispatch_once_t once = 0;
47+
dispatch_once(&once, ^{
48+
RNBranchConfig *config = RNBranchConfig.instance;
49+
50+
// YES if either [RNBranch useTestInstance] was called or useTestInstance: true is present in branch.json.
51+
BOOL usingTestInstance = useTestInstance || config.useTestInstance;
52+
NSString *key = usingTestInstance ? config.testKey : config.liveKey;
53+
54+
if (key) {
55+
// Override the Info.plist if these are present.
56+
RCTLog(@"Using Branch key %@ from branch.json", key);
57+
instance = [Branch getInstance: key];
58+
}
59+
else {
60+
instance = usingTestInstance ? [Branch getTestInstance] : [Branch getInstance];
61+
}
62+
63+
[self setupBranchInstance:instance];
64+
});
65+
return instance;
66+
}
6567
}
6668

6769
+ (void)setupBranchInstance:(Branch *)instance

0 commit comments

Comments
 (0)