Skip to content

Commit 7cd78a6

Browse files
author
Adrian Marquez
committed
Replace BranchKey tag with live, test and test mode tags
1 parent 4bd2439 commit 7cd78a6

File tree

6 files changed

+58
-6
lines changed

6 files changed

+58
-6
lines changed

src/index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const standardEvent = {
3131
var Branch = function Branch() {
3232
this.debugMode = false;
3333
this.trackingDisabled = false;
34+
this.sessionInitialized = false;
3435
};
3536

3637
// JavsSript to SDK wrappers
@@ -85,7 +86,15 @@ Branch.prototype.disableTracking = function disableTracking(isEnabled) {
8586
return execute("disableTracking", [value]);
8687
};
8788

89+
Branch.prototype.enableTestMode = function initSession() {
90+
if (this.sessionInitialized) {
91+
return executeReject("[enableTestMode] should be called before [initSession]");
92+
}
93+
return execute("enableTestMode");
94+
};
95+
8896
Branch.prototype.initSession = function initSession() {
97+
this.sessionInitialized = true;
8998
return execute("initSession");
9099
};
91100

src/ios/BranchSDK.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
@property (strong, nonatomic) NSMutableArray *branchUniversalObjArray;
2727

2828
// BranchSDK Basic Methods
29+
- (void)enableTestMode:(CDVInvokedUrlCommand*)command;
2930
- (void)initSession:(CDVInvokedUrlCommand*)command;
3031
- (void)disableTracking:(CDVInvokedUrlCommand*)command;
3132
- (void)setDebug:(CDVInvokedUrlCommand*)command;

src/ios/BranchSDK.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ - (void)continueUserActivity:(CDVInvokedUrlCommand*)command
8686
#pragma mark - Public APIs
8787
#pragma mark - Branch Basic Methods
8888

89+
- (void)enableTestMode:(CDVInvokedUrlCommand*)command
90+
{
91+
[Branch setUseTestBranchKey:TRUE];
92+
}
93+
8994
- (void)initSession:(CDVInvokedUrlCommand*)command
9095
{
9196
[[Branch getInstance] registerPluginName:@"CordovaIonic" version:pluginVersion];

src/scripts/android/updateAndroidManifest.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,14 @@
8787
const keys = ["io.branch.sdk.BranchKey", "io.branch.sdk.TestMode"];
8888
const vals = [
8989
preferences.branchKey,
90-
preferences.androidTestMode || "false"
90+
preferences.branchTestMode || preferences.androidTestMode || "false"
9191
];
9292

93+
if (preferences.branchKeyTest) {
94+
keys.push("io.branch.sdk.BranchKey.test");
95+
vals.push(preferences.branchKeyTest);
96+
}
97+
9398
// remove old
9499
for (var i = 0; i < keys.length; i++) {
95100
metadatas = removeBasedOnAndroidName(metadatas, keys[i]);

src/scripts/ios/updatePlist.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,15 @@
9090
}
9191

9292
// override
93-
obj.branch_key = preferences.branchKey;
93+
if (preferences.branchKeyTest) {
94+
obj.branch_key = {
95+
live: preferences.branchKey,
96+
test: preferences.branchKeyTest
97+
};
98+
} else {
99+
obj.branch_key = preferences.branchKey;
100+
}
101+
94102
obj.branch_app_domain = linkDomains[0];
95103

96104
return obj;

src/scripts/npm/processConfigXml.js

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@
5757
return {
5858
projectRoot: getProjectRoot(context),
5959
projectName: getProjectName(configXml),
60-
branchKey: getBranchValue(branchXml, "branch-key"),
60+
branchKey: getBranchKey(branchXml, "branch-key-live"),
61+
branchKeyTest: getBranchValue(branchXml, "branch-key-test"),
62+
branchTestMode: getBranchValue(branchXml, "branch-test-mode"),
6163
linkDomain: getBranchLinkDomains(branchXml, "link-domain"),
6264
androidLinkDomain: getBranchLinkDomains(branchXml, "android-link-domain"),
6365
iosLinkDomain: getBranchLinkDomains(branchXml, "ios-link-domain"),
@@ -68,7 +70,7 @@
6870
iosTeamDebug: getBranchValue(branchXml, "ios-team-debug"), // optional
6971
androidBundleId: getBundleId(configXml, "android"), // optional
7072
androidPrefix: getBranchValue(branchXml, "android-prefix"), // optional
71-
androidTestMode: getBranchValue(branchXml, "android-testmode") // optional
73+
androidTestMode: getBranchValue(branchXml, "android-testmode") // DEPRECATED optional
7274
};
7375
}
7476

@@ -99,6 +101,12 @@
99101
return branchXml.hasOwnProperty(key) ? branchXml[key][0].$.value : null;
100102
}
101103

104+
// read branch value from (<branch-key> DEPRECATED)
105+
// or <branch-key-live>
106+
function getBranchKey(branchXml) {
107+
return getBranchValue(branchXml, "branch-key-live") || getBranchValue(branchXml, "branch-key");
108+
}
109+
102110
// read branch value from <branch-config>
103111
// for multiple <link-domain>, <android-link-domain> or <ios-link-domain>
104112
function getBranchLinkDomains(branchXml, key) {
@@ -207,9 +215,14 @@
207215
'BRANCH SDK: Invalid "name" in your config.xml. Docs https://goo.gl/GijGKP'
208216
);
209217
}
210-
if (preferences.branchKey === null) {
218+
if (preferences.branchKey === null && preferences.branchKeyLive === null) {
219+
throw new Error(
220+
'BRANCH SDK: Invalid "branch-key-live" in <branch-config> in your config.xml. Docs https://goo.gl/GijGKP'
221+
);
222+
}
223+
if (preferences.branchKey === null && preferences.branchKeyTest === null) {
211224
throw new Error(
212-
'BRANCH SDK: Invalid "branch-key" in <branch-config> in your config.xml. Docs https://goo.gl/GijGKP'
225+
'BRANCH SDK: Invalid "branch-key-test" in <branch-config> in your config.xml. Docs https://goo.gl/GijGKP'
213226
);
214227
}
215228
if (
@@ -280,5 +293,16 @@
280293
'BRANCH SDK: Invalid "android-testmode" in <branch-config> in your config.xml. Docs https://goo.gl/GijGKP'
281294
);
282295
}
296+
if (
297+
!(
298+
preferences.branchTestMode === "true" ||
299+
preferences.branchTestMode === "false" ||
300+
preferences.branchTestMode === null
301+
)
302+
) {
303+
throw new Error(
304+
'BRANCH SDK: Invalid "branch-test-mode" in <branch-config> in your config.xml. Docs https://goo.gl/GijGKP'
305+
);
306+
}
283307
}
284308
})();

0 commit comments

Comments
 (0)