Skip to content

Commit 54640db

Browse files
authored
Merge pull request #480 from BranchMetrics/synchronous-option-for-get-latest-referring-params
Synchronous option for get latest referring params
2 parents 8a01c2a + 4467f2e commit 54640db

File tree

4 files changed

+20
-7
lines changed

4 files changed

+20
-7
lines changed

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -504,21 +504,27 @@ These session parameters will be available at any point later on with this comma
504504
#### Method
505505

506506
```js
507-
branch.getLatestReferringParams()
507+
branch.getLatestReferringParams(synchronous = false)
508508
```
509509

510510
##### Return
511511

512512
A promise. On resolution, the promise returns an object containing the parameters
513513
from the latest link open or install. See [Params object](#params-object) for
514-
details on the contents.
514+
details on the contents. Depending on the value of the argument, the promise may
515+
return right away, possibly with values from the user defaults (iOS) or user
516+
preferences (Android) or wait until an open response is received.
515517

516518
#### Example
517519

518520
```js
519521
import branch from 'react-native-branch'
520522

523+
// don't wait for open response
521524
const latestParams = await branch.getLatestReferringParams()
525+
526+
// wait for open response
527+
const latestParams = await branch.getLatestReferringParams(true)
522528
```
523529

524530
___

android/src/main/java/io/branch/rnbranch/RNBranchModule.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,9 +349,12 @@ public void redeemInitSessionResult(Promise promise) {
349349
}
350350

351351
@ReactMethod
352-
public void getLatestReferringParams(Promise promise) {
352+
public void getLatestReferringParams(boolean synchronous, Promise promise) {
353353
Branch branch = Branch.getInstance();
354-
promise.resolve(convertJsonToMap(branch.getLatestReferringParamsSync()));
354+
if (synchronous)
355+
promise.resolve(convertJsonToMap(branch.getLatestReferringParamsSync()));
356+
else
357+
promise.resolve(convertJsonToMap(branch.getLatestReferringParams()));
355358
}
356359

357360
@ReactMethod

ios/RNBranch.m

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,10 +349,14 @@ - (BranchUniversalObject *)findUniversalObjectWithIdent:(NSString *)ident reject
349349

350350
#pragma mark getLatestReferringParams
351351
RCT_EXPORT_METHOD(
352-
getLatestReferringParams:(RCTPromiseResolveBlock)resolve
352+
getLatestReferringParams:(NSNumber* __nonnull)synchronous
353+
resolver:(RCTPromiseResolveBlock)resolve
353354
rejecter:(__unused RCTPromiseRejectBlock)reject
354355
) {
355-
resolve([self.class.branch getLatestReferringParamsSynchronous]);
356+
if (synchronous.boolValue)
357+
resolve([self.class.branch getLatestReferringParamsSynchronous]);
358+
else
359+
resolve([self.class.branch getLatestReferringParams]);
356360
}
357361

358362
#pragma mark getFirstReferringParams

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ class Branch {
107107

108108
/*** RNBranch singleton methods ***/
109109
setDebug = () => { throw 'setDebug() is not supported in the RN SDK. For other solutions, please see https://rnbranch.app.link/setDebug' }
110-
getLatestReferringParams = RNBranch.getLatestReferringParams
110+
getLatestReferringParams = (synchronous = false) => RNBranch.getLatestReferringParams(synchronous)
111111
getFirstReferringParams = RNBranch.getFirstReferringParams
112112
setIdentity = (identity) => RNBranch.setIdentity(identity)
113113
logout = RNBranch.logout

0 commit comments

Comments
 (0)