@@ -52,6 +52,8 @@ static class BranchLinkProperties extends io.branch.referral.util.LinkProperties
52
52
private Activity activity ;
53
53
private Branch instance ;
54
54
private String deepLinkUrl ;
55
+ private CallbackContext initSessionCallbackContext ;
56
+ private boolean initSessionCallbackContextKeepCallback ;
55
57
56
58
/**
57
59
* Class Constructor
@@ -61,7 +63,8 @@ public BranchSDK() {
61
63
this .activity = null ;
62
64
this .instance = null ;
63
65
this .branchObjectWrappers = new ArrayList <BranchUniversalObjectWrapper >();
64
-
66
+ this .initSessionCallbackContext = null ;
67
+ this .initSessionCallbackContextKeepCallback = false ;
65
68
}
66
69
67
70
/**
@@ -84,6 +87,7 @@ protected void pluginInitialize() {
84
87
public void onNewIntent (Intent intent ) {
85
88
intent .putExtra ("branch_force_new_session" , true );
86
89
this .activity .setIntent (intent );
90
+ Branch .sessionBuilder (this .activity ).withCallback (branchReferralInitListener ).reInit ();
87
91
}
88
92
89
93
/**
@@ -279,7 +283,7 @@ public void lastAttributedTouchData(CallbackContext callbackContext) {
279
283
*
280
284
* @param callbackContext A callback to execute at the end of this method
281
285
*/
282
- private void initSession (CallbackContext callbackContext ) {
286
+ private void initSession (boolean isKeepCallBack , CallbackContext callbackContext ) {
283
287
284
288
this .activity = this .cordova .getActivity ();
285
289
@@ -289,9 +293,35 @@ private void initSession(CallbackContext callbackContext) {
289
293
this .deepLinkUrl = data .toString ();
290
294
}
291
295
292
- this .instance .initSession (new SessionListener (callbackContext ), data , activity );
296
+ this .initSessionCallbackContext = callbackContext ;
297
+ this .initSessionCallbackContextKeepCallback = isKeepCallBack ;
298
+
299
+ Branch .sessionBuilder (activity ).withCallback (branchReferralInitListener ).withData (data ).init ();
293
300
}
294
301
302
+ private Branch .BranchReferralInitListener branchReferralInitListener = new Branch .BranchReferralInitListener () {
303
+ @ Override
304
+ public void onInitFinished (JSONObject referringParams , BranchError error ) {
305
+ if (error == null && referringParams != null && initSessionCallbackContext != null ) {
306
+ PluginResult result = new PluginResult (PluginResult .Status .OK , referringParams );
307
+ if (initSessionCallbackContextKeepCallback ){
308
+ result .setKeepCallback (true );
309
+ }
310
+ initSessionCallbackContext .sendPluginResult (result );
311
+ } else {
312
+ JSONObject message = new JSONObject ();
313
+ try {
314
+ message .put ("error" , error .getMessage ());
315
+ } catch (JSONException e ) {
316
+ e .printStackTrace ();
317
+ }
318
+ if (initSessionCallbackContext != null ) {
319
+ initSessionCallbackContext .error (message );
320
+ }
321
+ }
322
+ }
323
+ };
324
+
295
325
/**
296
326
* <p>This method should be called if you know that a different person is about to use the app. For example,
297
327
* if you allow users to log out and let their friend use the app, you should call this to notify Branch
@@ -618,7 +648,7 @@ private void setCookieBasedMatching(String linkDomain, CallbackContext callbackC
618
648
*/
619
649
private void setDebug (boolean isEnable , CallbackContext callbackContext ) {
620
650
this .activity = this .cordova .getActivity ();
621
- Branch .enableDebugMode ();
651
+ Branch .enableLogging ();
622
652
callbackContext .sendPluginResult (new PluginResult (PluginResult .Status .OK , isEnable ));
623
653
}
624
654
@@ -653,7 +683,7 @@ private void setIdentity(String newIdentity, CallbackContext callbackContext) {
653
683
/**
654
684
* <p>Allow Branch SDK to pass the user's Mixpanel distinct id to our servers. Branch will then pass that Distinct ID to Mixpanel when logging any event.</p>
655
685
*
656
- * @param token A {@link String} value containing the unique identifier of the Mixpanel user.
686
+ * @param key A {@link String} value containing the unique identifier of the Mixpanel user.
657
687
* @param callbackContext A callback to execute at the end of this method
658
688
*/
659
689
private void setRequestMetadata (String key , String val , CallbackContext callbackContext ) {
@@ -1423,7 +1453,8 @@ public void run() {
1423
1453
} else if (this .action .equals ("disableTracking" )) {
1424
1454
disableTracking (this .args .getBoolean (0 ), this .callbackContext );
1425
1455
} else if (this .action .equals ("initSession" )) {
1426
- initSession (this .callbackContext );
1456
+ boolean keepCallBack = this .args .length () != 0 && this .args .getBoolean (0 );
1457
+ initSession (keepCallBack , this .callbackContext );
1427
1458
} else if (this .action .equals ("setRequestMetadata" )) {
1428
1459
setRequestMetadata (this .args .getString (0 ), this .args .getString (1 ), this .callbackContext );
1429
1460
} else {
0 commit comments