Skip to content

Commit 4d3b037

Browse files
Merge pull request #732 from BranchMetrics/SDK-1562
[SDK-1562] Add callback to setIdentity
2 parents dda9499 + d0adfe7 commit 4d3b037

File tree

4 files changed

+32
-0
lines changed

4 files changed

+32
-0
lines changed

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,21 @@ public void setIdentity(String identity) {
445445
branch.setIdentity(identity);
446446
}
447447

448+
@ReactMethod
449+
public void setIdentityAsync(String identity, Promise promise) {
450+
Branch branch = Branch.getInstance();
451+
branch.setIdentity(identity, new BranchReferralInitListener() {
452+
@Override
453+
public void onInitFinished(JSONObject referringParams, BranchError error) {
454+
if (error != null) {
455+
promise.reject("RNBranch::Error::setIdentityAsync failed", error.getMessage());
456+
} else {
457+
promise.resolve(convertJsonToMap(referringParams));
458+
}
459+
}
460+
});
461+
}
462+
448463
@ReactMethod
449464
public void setRequestMetadataKey(String key, String value) {
450465
// setRequestMetadata does not do what it appears to do. Call directly to the native code.

ios/RNBranch.m

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,21 @@ - (BranchUniversalObject *)findUniversalObjectWithIdent:(NSString *)ident reject
407407
[self.class.branch setIdentity:identity];
408408
}
409409

410+
#pragma mark setIdentityAsync
411+
RCT_EXPORT_METHOD(
412+
setIdentityAsync:(NSString *)identity
413+
resolver:(RCTPromiseResolveBlock)resolve
414+
rejecter:(__unused RCTPromiseRejectBlock)reject
415+
) {
416+
[self.class.branch setIdentity: identity withCallback:^(NSDictionary *params, NSError *error) {
417+
if (!error) {
418+
resolve(params);
419+
} else {
420+
reject(@"RNBranch::Error::setIdentityAsync failed", error.localizedDescription, error);
421+
}
422+
}];
423+
}
424+
410425
#pragma mark setRequestMetadataKey
411426
RCT_EXPORT_METHOD(
412427
setRequestMetadataKey:(NSString *)key

src/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ interface Branch {
322322
getFirstReferringParams: () => Promise<BranchParams>;
323323
lastAttributedTouchData: (attributionWindow?: number) => Promise<BranchParams>;
324324
setIdentity: (identity: string) => void;
325+
setIdentityAsync: (identity: string) => Promise<BranchParams>;
325326
setRequestMetadata: (key: string, value: string) => void;
326327
addFacebookPartnerParameter: (name: string, value: string) => void;
327328
clearPartnerParameters: () => void;

src/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class Branch {
6262
getFirstReferringParams = RNBranch.getFirstReferringParams
6363
lastAttributedTouchData = (attributionWindow = {}) => RNBranch.lastAttributedTouchData(attributionWindow)
6464
setIdentity = (identity) => RNBranch.setIdentity(identity)
65+
setIdentityAsync = (identity) => RNBranch.setIdentityAsync(identity)
6566
setRequestMetadata = (key, value) => {
6667
console.info('[Branch] setRequestMetadata has limitations when called from JS. Some network calls are made prior to the JS layer being available, those calls will not have the metadata.')
6768
return RNBranch.setRequestMetadataKey(key, value)

0 commit comments

Comments
 (0)