diff --git a/android/build.gradle b/android/build.gradle index ba5e1d73a..e92c399bf 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -47,5 +47,5 @@ def safeExtGet(prop, fallback) { dependencies { implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.0.0' implementation 'com.facebook.react:react-native:+' // From node_modules - api 'io.branch.sdk.android:library:5.9.0' + api 'io.branch.sdk.android:library:5.10.1' } diff --git a/android/src/main/java/io/branch/rnbranch/RNBranchModule.java b/android/src/main/java/io/branch/rnbranch/RNBranchModule.java index e3bb4c8ad..f9232e0c5 100644 --- a/android/src/main/java/io/branch/rnbranch/RNBranchModule.java +++ b/android/src/main/java/io/branch/rnbranch/RNBranchModule.java @@ -1251,4 +1251,9 @@ public void setDMAParamsForEEA(boolean eeaRegion, boolean adPersonalizationConse Branch branch = Branch.getInstance(); branch.setDMAParamsForEEA(eeaRegion, adPersonalizationConsent, adUserDataUsageConsent); } + + @ReactMethod + public void setAPIUrl(String apiUrl) { + Branch.setAPIUrl(apiUrl + "/"); + } } diff --git a/branchreactnativetestbed/components/BranchWrapper.ts b/branchreactnativetestbed/components/BranchWrapper.ts index c290ee0f5..ee86fe693 100644 --- a/branchreactnativetestbed/components/BranchWrapper.ts +++ b/branchreactnativetestbed/components/BranchWrapper.ts @@ -11,7 +11,8 @@ export default class BranchWrapper { componentDidMount() { console.log('BranchWrapper componentDidMount'); - + branch.setAPIUrl('https://api3.branch.io'); + this._unsubscribeFromBranch = branch.subscribe({ onOpenStart: ({uri, cachedInitialEvent}) => { console.log( diff --git a/ios/RNBranch.m b/ios/RNBranch.m index 9dfdb9dd6..e12ac0ea4 100644 --- a/ios/RNBranch.m +++ b/ios/RNBranch.m @@ -744,4 +744,9 @@ - (CGFloat) colorComponentFrom: (NSString *) string start: (NSUInteger) start le [Branch setDMAParamsForEEA:eeaRegion AdPersonalizationConsent:adPersonalizationConsent AdUserDataUsageConsent:adUserDataUsageConsent]; } +#pragma mark setAPIUrl +RCT_EXPORT_METHOD(setAPIUrl:(NSString *)apiUrl) { + [Branch setAPIUrl:apiUrl]; +} + @end diff --git a/src/index.d.ts b/src/index.d.ts index bf290029f..1120c1a9f 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -348,6 +348,7 @@ interface Branch { setPreInstallCampaign: (campaign: string) => void; setPreInstallPartner: (partner: string) => void; setDMAParamsForEEA: (eeaRegion: boolean, adPersonalizationConsent: boolean, adUserDataUsageConsent: boolean) => void; + setAPIUrl: (url: string) => void; } declare const branch: Branch; export default branch; diff --git a/src/index.js b/src/index.js index 835a59432..99facb6d4 100644 --- a/src/index.js +++ b/src/index.js @@ -164,6 +164,17 @@ class Branch { console.warn("setDMAParamsForEEA: Unable to set DMA params."); } }; + + /*** Set the Branch API's base URL (eg. "https://api2.branch.io") ***/ + setAPIUrl = (apiUrl) => { + if (!apiUrl || typeof apiUrl !== "string" || !apiUrl.startsWith("http")) { + console.warn( + "setAPIUrl: Invalid URL. URL must be a non-empty string starting with 'http'." + ); + return; + } + RNBranch.setAPIUrl(apiUrl); + }; } const validateParam = (param, paramName) => {