Skip to content

Commit 8bf7398

Browse files
authored
Merge pull request #651 from adrianyg7/sdk593
Cordova Feature Requests - iOS Session Override + Platform-specific Domains - SDK-593
2 parents d4c0853 + 7cd78a6 commit 8bf7398

File tree

7 files changed

+78
-13
lines changed

7 files changed

+78
-13
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: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,15 @@ - (id)handleDeepLink:(CDVInvokedUrlCommand*)command
5858
return [NSNumber numberWithBool:[[Branch getInstance] handleDeepLink:url]];
5959
}
6060

61+
- (id)handleDeepLinkWithNewSession:(CDVInvokedUrlCommand*)command
62+
{
63+
NSString *arg = [command.arguments objectAtIndex:0];
64+
NSURL *url = [NSURL URLWithString:arg];
65+
self.deepLinkUrl = [url absoluteString];
66+
67+
return [NSNumber numberWithBool:[[Branch getInstance] handleDeepLinkWithNewSession:url]];
68+
}
69+
6170
- (void)continueUserActivity:(CDVInvokedUrlCommand*)command
6271
{
6372

@@ -77,6 +86,11 @@ - (void)continueUserActivity:(CDVInvokedUrlCommand*)command
7786
#pragma mark - Public APIs
7887
#pragma mark - Branch Basic Methods
7988

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

src/scripts/android/updateAndroidManifest.js

Lines changed: 7 additions & 2 deletions
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]);
@@ -248,7 +253,7 @@
248253
// determine the Branch link domain <data> to append to the App Link intent filter
249254
function getAppLinkIntentFilterData(preferences) {
250255
const intentFilterData = [];
251-
const linkDomains = preferences.linkDomain;
256+
const linkDomains = [...preferences.androidLinkDomain, ...preferences.linkDomain];
252257

253258
for (let i = 0; i < linkDomains.length; i++) {
254259
const linkDomain = linkDomains[i];

src/scripts/ios/updateAssociatedDomains.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
// removed previous associated domains related to Branch (will not remove link domain changes from custom domains or custom sub domains)
9292
function removePreviousAssociatedDomains(preferences, domains) {
9393
const output = [];
94-
const linkDomains = preferences.linkDomain;
94+
const linkDomains = [...preferences.iosLinkDomain, ...preferences.linkDomain];
9595

9696
if (!domains) return output;
9797
for (let i = 0; i < domains.length; i++) {
@@ -122,7 +122,7 @@
122122
function updateAssociatedDomains(preferences) {
123123
const domainList = [];
124124
const prefix = "applinks:";
125-
const linkDomains = preferences.linkDomain;
125+
const linkDomains = [...preferences.iosLinkDomain, ...preferences.linkDomain];
126126

127127
for (let i = 0; i < linkDomains.length; i++) {
128128
const linkDomain = linkDomains[i];

src/scripts/ios/updatePlist.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@
6161
CFBundleURLName: SDK,
6262
CFBundleURLSchemes: [preferences.uriScheme]
6363
};
64+
// ios specific domain will be preferred
65+
const linkDomains = [...preferences.iosLinkDomain, ...preferences.linkDomain];
6466

6567
if (!obj.hasOwnProperty("CFBundleURLTypes")) {
6668
// add
@@ -88,8 +90,16 @@
8890
}
8991

9092
// override
91-
obj.branch_key = preferences.branchKey;
92-
obj.branch_app_domain = preferences.linkDomain[0];
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+
102+
obj.branch_app_domain = linkDomains[0];
93103

94104
return obj;
95105
}

src/scripts/npm/processConfigXml.js

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,20 @@
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"),
64+
androidLinkDomain: getBranchLinkDomains(branchXml, "android-link-domain"),
65+
iosLinkDomain: getBranchLinkDomains(branchXml, "ios-link-domain"),
6266
uriScheme: getBranchValue(branchXml, "uri-scheme"),
6367
iosBundleId: getBundleId(configXml, "ios"),
6468
iosProjectModule: getProjectModule(context),
6569
iosTeamRelease: getBranchValue(branchXml, "ios-team-release"), // optional
6670
iosTeamDebug: getBranchValue(branchXml, "ios-team-debug"), // optional
6771
androidBundleId: getBundleId(configXml, "android"), // optional
6872
androidPrefix: getBranchValue(branchXml, "android-prefix"), // optional
69-
androidTestMode: getBranchValue(branchXml, "android-testmode") // optional
73+
androidTestMode: getBranchValue(branchXml, "android-testmode") // DEPRECATED optional
7074
};
7175
}
7276

@@ -97,7 +101,14 @@
97101
return branchXml.hasOwnProperty(key) ? branchXml[key][0].$.value : null;
98102
}
99103

100-
// read branch value from <branch-config> for multiple <link-domain>
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+
110+
// read branch value from <branch-config>
111+
// for multiple <link-domain>, <android-link-domain> or <ios-link-domain>
101112
function getBranchLinkDomains(branchXml, key) {
102113
const output = [];
103114
if (branchXml.hasOwnProperty(key)) {
@@ -204,9 +215,14 @@
204215
'BRANCH SDK: Invalid "name" in your config.xml. Docs https://goo.gl/GijGKP'
205216
);
206217
}
207-
if (preferences.branchKey === null) {
218+
if (preferences.branchKey === null && preferences.branchKeyLive === null) {
208219
throw new Error(
209-
'BRANCH SDK: Invalid "branch-key" in <branch-config> in your config.xml. Docs https://goo.gl/GijGKP'
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) {
224+
throw new Error(
225+
'BRANCH SDK: Invalid "branch-key-test" in <branch-config> in your config.xml. Docs https://goo.gl/GijGKP'
210226
);
211227
}
212228
if (
@@ -218,9 +234,8 @@
218234
);
219235
}
220236
if (
221-
preferences.linkDomain === null ||
222237
!/^(?!.*?www).*([a-zA-Z0-9]+(\.[a-zA-Z0-9]+)+.*)$/.test(
223-
preferences.linkDomain
238+
[...preferences.linkDomain, ...preferences.androidLinkDomain, preferences.iosLinkDomain]
224239
)
225240
) {
226241
throw new Error(
@@ -278,5 +293,16 @@
278293
'BRANCH SDK: Invalid "android-testmode" in <branch-config> in your config.xml. Docs https://goo.gl/GijGKP'
279294
);
280295
}
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+
}
281307
}
282308
})();

0 commit comments

Comments
 (0)