From c6290ae27d444ea5b5f23ac191d7f18abaef09ce Mon Sep 17 00:00:00 2001 From: pragunvohra Date: Fri, 25 Mar 2016 11:14:32 -0400 Subject: [PATCH] resolve setDebug promise on Android & ios with passed-in value MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Worth noting that it looks like doing the following: initSession() setDebug(true) setDebug(false) will currently leave the debug state as true since false is pretty much a no-op. This commit at least fixes (on iOS) so that if you do initSession() then setDebug(false), it doesn’t set debug mode to on. Both platforms now return a proper bool value of true/false. --- src/android/io/branch/BranchSDK.java | 6 ++++-- src/ios/BranchSDK.m | 10 +++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/android/io/branch/BranchSDK.java b/src/android/io/branch/BranchSDK.java index 9452c7ef..8fbabdbb 100644 --- a/src/android/io/branch/BranchSDK.java +++ b/src/android/io/branch/BranchSDK.java @@ -111,7 +111,7 @@ public boolean execute(String action, JSONArray args, CallbackContext callbackCo if (action.equals("setDebug")) { if (args.length() == 1) { - this.setDebug(args.getBoolean(0)); + this.setDebug(args.getBoolean(0), callbackContext); } return true; } else if (action.equals("initSession")) { @@ -577,8 +577,9 @@ private void generateShortUrl(JSONObject options, JSONObject controlParams, Call *

If you want to flag debug, call this before initUserSession

* * @param isEnable A {@link Boolean} value to enable/disable debugging mode for the app. + * @param callbackContext A callback to execute at the end of this method */ - private void setDebug(boolean isEnable) + private void setDebug(boolean isEnable, CallbackContext callbackContext) { Log.d(LCAT, "start setDebug()"); @@ -591,6 +592,7 @@ private void setDebug(boolean isEnable) debugInstance.setDebug(); } + callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, /* send boolean: false as the data */ isEnable)); } /** diff --git a/src/ios/BranchSDK.m b/src/ios/BranchSDK.m index 2f654029..21e1f6d2 100644 --- a/src/ios/BranchSDK.m +++ b/src/ios/BranchSDK.m @@ -122,7 +122,15 @@ - (void)initSession:(CDVInvokedUrlCommand*)command - (void)setDebug:(CDVInvokedUrlCommand*)command { NSLog(@"start setDebug"); - [[Branch getInstance] setDebug]; + CDVPluginResult* pluginResult; + bool enableDebug = [[command.arguments objectAtIndex:0] boolValue] == YES; + if (enableDebug) { + [[Branch getInstance] setDebug]; + } + + pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsBool:enableDebug]; + + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; } - (void)getAutoInstance:(CDVInvokedUrlCommand*)command