Skip to content

Commit 0081fcd

Browse files
authored
Merge pull request #217 from BranchMetrics/add-back-setdebug
feat: Add setDebug back
2 parents e7482f5 + 37bb1a2 commit 0081fcd

File tree

16 files changed

+110
-13
lines changed

16 files changed

+110
-13
lines changed

README.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ Branch.getFirstReferringParams().then(function (res) {
152152
## Plugin Methods
153153

154154
1. Branch Session
155+
+ [setDebug](#setDebug)
155156
+ [initSession](#initSession)
156157
+ [setMixpanelToken](#setMixpanelToken)
157158
+ [getLatestReferringParams](#getLatestReferringParams)
@@ -172,9 +173,23 @@ Branch.getFirstReferringParams().then(function (res) {
172173
4. FAQ
173174
+ [Android Build FAQ](#android-build-faq)
174175

176+
### <a id="setDebug"></a>setDebug(isEnable)
177+
178+
Setting the SDK debug flag will generate a new device ID each time the app is installed instead of possibly using the same device id. This is useful when testing.
179+
180+
**Parameters**
181+
182+
**options**: `boolean` - Boolean flag if debug mode should be enabled or not.
183+
184+
##### Usage
185+
186+
```js
187+
Branch.setDebug(true);
188+
```
189+
175190
### <a id="initSession"></a>initSession()
176191

177-
Initializes the branch instance.
192+
Initializes the branch instance. **Note:** `setDebug()` should be called first before calling this method.
178193

179194
##### Usage
180195
The `initSession()` method automatically sets an internal deep link hander whose data can be accesed by implementing the **required** `DeepLinkHandler()` method. To implement this, first call the method `initSession`:

src/android/io/branch/BranchSDK.java

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,12 @@ public boolean execute(String action, JSONArray args, CallbackContext callbackCo
8484

8585
Runnable r = new RunnableThread(action, args, callbackContext);
8686

87-
if (action.equals("initSession")) {
87+
if (action.equals("setDebug")) {
88+
if (args.length() == 1) {
89+
cordova.getThreadPool().execute(r);
90+
}
91+
return true;
92+
} else if (action.equals("initSession")) {
8893
cordova.getThreadPool().execute(r);
8994
return true;
9095
} else if (action.equals("setMixpanelToken")) {
@@ -525,6 +530,27 @@ private void generateShortUrl(int instanceIdx, JSONObject options, JSONObject co
525530

526531
}
527532

533+
/**
534+
* <p>Sets the library to function in debug mode, enabling logging of all requests.</p>
535+
* <p>If you want to flag debug, call this <b>before</b> initUserSession</p>
536+
*
537+
* @param isEnable A {@link Boolean} value to enable/disable debugging mode for the app.
538+
* @param callbackContext A callback to execute at the end of this method
539+
*/
540+
private void setDebug(boolean isEnable, CallbackContext callbackContext)
541+
{
542+
543+
this.activity = this.cordova.getActivity();
544+
545+
Branch debugInstance = Branch.getAutoInstance(this.activity.getApplicationContext());
546+
547+
if (isEnable) {
548+
debugInstance.setDebug();
549+
}
550+
551+
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, /* send boolean: false as the data */ isEnable));
552+
}
553+
528554
/**
529555
* <p>Identifies the current user to the Branch API by supplying a unique
530556
* identifier as a {@link String} value.</p>
@@ -1090,7 +1116,9 @@ public RunnableThread(String action, JSONArray args, CallbackContext callbackCon
10901116

10911117
public void run() {
10921118
try {
1093-
if (this.action.equals("initSession")) {
1119+
if (this.action.equals("setDebug")) {
1120+
setDebug(this.args.getBoolean(0), this.callbackContext);
1121+
} else if (this.action.equals("initSession")) {
10941122
initSession(this.callbackContext);
10951123
} else if (this.action.equals("setMixpanelToken")) {
10961124
setMixpanelToken(this.args.getString(0), this.callbackContext);

src/ios/BranchSDK.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
// BranchSDK Basic Methods
3636
- (void)initSession:(CDVInvokedUrlCommand*)command;
3737
- (void)setMixpanelToken:(CDVInvokedUrlCommand*)command;
38+
- (void)setDebug:(CDVInvokedUrlCommand*)command;
3839
- (void)getAutoInstance:(CDVInvokedUrlCommand*)command;
3940
- (void)getLatestReferringParams:(CDVInvokedUrlCommand*)command;
4041
- (void)getFirstReferringParams:(CDVInvokedUrlCommand*)command;

src/ios/BranchSDK.m

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,18 @@ - (void)setMixpanelToken:(CDVInvokedUrlCommand*)command
150150

151151
}
152152

153+
- (void)setDebug:(CDVInvokedUrlCommand*)command
154+
{
155+
bool enableDebug = [[command.arguments objectAtIndex:0] boolValue] == YES;
156+
if (enableDebug) {
157+
[[Branch getInstance] setDebug];
158+
}
159+
160+
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsBool:enableDebug];
161+
162+
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
163+
}
164+
153165
- (void)getAutoInstance:(CDVInvokedUrlCommand*)command
154166
{
155167
[self initSession:nil];

src/ios/dependencies/Branch-SDK/BNCConfig.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#ifndef Branch_SDK_Config_h
1010
#define Branch_SDK_Config_h
1111

12-
#define SDK_VERSION @"0.12.10"
12+
#define SDK_VERSION @"0.12.11"
1313

1414
#define BNC_PROD_ENV
1515
//#define BNC_STAGE_ENV

src/ios/dependencies/Branch-SDK/BNCPreferenceHelper.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
@property (assign, nonatomic) NSTimeInterval timeout;
3737
@property (strong, nonatomic) NSString *externalIntentURI;
3838
@property (strong, nonatomic) NSMutableDictionary *savedAnalyticsData;
39+
@property (assign, nonatomic) NSInteger installRequestDelay;
3940

4041
+ (BNCPreferenceHelper *)preferenceHelper;
4142

src/ios/dependencies/Branch-SDK/BNCStrongMatchHelper.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ - (void)presentSafariVCWithBranchKey:(NSString *)branchKey {
135135
[self.secondWindow makeKeyWindow];
136136

137137
// Give enough time for Safari to load the request (optimized for 3G)
138-
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
138+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
139139
[keyWindow makeKeyWindow];
140140

141141
// Remove the window and release it's strong reference. This is important to ensure that

src/ios/dependencies/Branch-SDK/Branch.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ typedef NS_ENUM(NSUInteger, BranchCreditHistoryOrder) {
448448
but that UL is not a Facebook UL. Some developers prefer not to modify
449449
`application:didFinishLaunchingWithOptions:` to always return `YES` and should use this method instead.
450450
*/
451-
- (void)accountForFacebookSDKPreventingAppLaunch;
451+
- (void)accountForFacebookSDKPreventingAppLaunch __attribute__((deprecated(("Please ensure application:didFinishLaunchingWithOptions: always returns YES/true instead of using this method. It will be removed in a future release."))));
452452

453453
- (void)suppressWarningLogs;
454454

@@ -468,6 +468,8 @@ typedef NS_ENUM(NSUInteger, BranchCreditHistoryOrder) {
468468

469469
- (void)resumeInit;
470470

471+
- (void)setInstallRequestDelay:(NSInteger)installRequestDelay;
472+
471473
#pragma mark - Session Item methods
472474

473475
///--------------------

src/ios/dependencies/Branch-SDK/Branch.m

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,9 @@ - (void)resumeInit {
271271
}
272272
}
273273

274+
- (void)setInstallRequestDelay:(NSInteger)installRequestDelay {
275+
self.preferenceHelper.installRequestDelay = installRequestDelay;
276+
}
274277

275278
#pragma mark - InitSession Permutation methods
276279

@@ -336,14 +339,15 @@ - (void)initSessionWithLaunchOptions:(NSDictionary *)options isReferrable:(BOOL)
336339
}
337340

338341
if ([BNCSystemObserver getOSVersion].integerValue >= 8) {
339-
if (![options objectForKey:UIApplicationLaunchOptionsURLKey] && ![options objectForKey:UIApplicationLaunchOptionsUserActivityDictionaryKey]) {
342+
if (![options.allKeys containsObject:UIApplicationLaunchOptionsURLKey] && ![options.allKeys containsObject:UIApplicationLaunchOptionsUserActivityDictionaryKey]) {
340343
// If Facebook SDK is present, call deferred app link check here
341344
if (![self checkFacebookAppLinks]) {
342345
[self initUserSessionAndCallCallback:YES];
343346
}
344347
}
345-
else if ([options objectForKey:UIApplicationLaunchOptionsUserActivityDictionaryKey]) {
348+
else if ([options.allKeys containsObject:UIApplicationLaunchOptionsUserActivityDictionaryKey]) {
346349
if (self.accountForFacebookSDK) {
350+
// does not work in Swift, because Objective-C to Swift interop is bad
347351
id activity = [[options objectForKey:UIApplicationLaunchOptionsUserActivityDictionaryKey] objectForKey:@"UIApplicationLaunchOptionsUserActivityKey"];
348352
if (activity && [activity isKindOfClass:[NSUserActivity class]]) {
349353
[self continueUserActivity:activity];
@@ -353,7 +357,7 @@ - (void)initSessionWithLaunchOptions:(NSDictionary *)options isReferrable:(BOOL)
353357
self.preferenceHelper.shouldWaitForInit = YES;
354358
}
355359
}
356-
else if (![options objectForKey:UIApplicationLaunchOptionsURLKey]) {
360+
else if (![options.allKeys containsObject:UIApplicationLaunchOptionsURLKey]) {
357361
[self initUserSessionAndCallCallback:YES];
358362
}
359363
}
@@ -1364,7 +1368,7 @@ + (NSString *)bundleIdentifier {
13641368
}
13651369

13661370
+ (NSString *)kitDisplayVersion {
1367-
return @"0.12.10";
1371+
return @"0.12.11";
13681372
}
13691373

13701374
@end

src/ios/dependencies/Branch-SDK/Requests/BranchInstallRequest.m

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ - (void)makeRequest:(BNCServerInterface *)serverInterface key:(NSString *)key ca
3636
params[BRANCH_REQUEST_KEY_DEBUG] = @(preferenceHelper.isDebug);
3737

3838
if ([[BNCStrongMatchHelper strongMatchHelper] shouldDelayInstallRequest]) {
39-
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(750 * NSEC_PER_MSEC)), dispatch_get_main_queue(), ^{
39+
NSInteger delay = 750;
40+
if (preferenceHelper.installRequestDelay) {
41+
delay = preferenceHelper.installRequestDelay;
42+
}
43+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delay * NSEC_PER_MSEC)), dispatch_get_main_queue(), ^{
4044
[serverInterface postRequest:params url:[preferenceHelper getAPIURL:BRANCH_REQUEST_ENDPOINT_INSTALL] key:key callback:callback];
4145
});
4246
}

0 commit comments

Comments
 (0)