Skip to content

Commit 3d593dd

Browse files
authored
Merge pull request #646 from adrianyg7/sdk849
Change Android API, report plugin version programmatically
2 parents 822365b + c37243b commit 3d593dd

File tree

5 files changed

+86
-7
lines changed

5 files changed

+86
-7
lines changed

plugin.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ SOFTWARE.
4040
</engines>
4141

4242
<!-- Hooks -->
43+
<hook src="src/scripts/hooks/beforePluginInstall.js" type="before_plugin_install" />
4344
<hook src="src/scripts/hooks/beforePrepare.js" type="after_plugin_install" />
4445
<hook src="src/scripts/hooks/afterPrepare.js" type="after_plugin_add" />
4546
<hook src="src/scripts/hooks/beforePrepare.js" type="before_prepare" />
@@ -62,7 +63,7 @@ SOFTWARE.
6263
<!-- Manifest configuration is done via a js script. We should move it to this config in the future. -->
6364

6465
<source-file src="src/android/io/branch/BranchSDK.java" target-dir="src/io/branch" />
65-
<framework src="io.branch.sdk.android:library:4.3.2"/>
66+
<framework src="io.branch.sdk.android:library:4.4.0"/>
6667
</platform>
6768

6869
<!-- iOS -->

src/android/io/branch/BranchSDK.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
import io.branch.indexing.BranchUniversalObject;
2222
import io.branch.referral.Branch;
23-
import io.branch.referral.BranchUtil;
2423
import io.branch.referral.PrefHelper;
2524
import io.branch.referral.BranchError;
2625
import io.branch.referral.BranchViewHandler;
@@ -44,8 +43,9 @@ static class BranchLinkProperties extends io.branch.referral.util.LinkProperties
4443

4544
// Standard Debugging Variables
4645
private static final String LCAT = "CordovaBranchSDK";
47-
// todo pick up plugin version dynamically
48-
private static final String BRANCH_PLUGIN_VERSION = "4.1.3";
46+
47+
private static final String BRANCH_PLUGIN_TYPE = "CordovaIonic";
48+
private static final String BRANCH_PLUGIN_VERSION = "%BRANCH_PLUGIN_VERSION%";
4949

5050
// Private Method Properties
5151
private ArrayList<BranchUniversalObjectWrapper> branchObjectWrappers;
@@ -72,8 +72,7 @@ protected void pluginInitialize() {
7272

7373
this.activity = this.cordova.getActivity();
7474
Branch.disableInstantDeepLinking(true);
75-
BranchUtil.setPluginType(BranchUtil.PluginType.CordovaIonic);
76-
BranchUtil.setPluginVersion(BRANCH_PLUGIN_VERSION);
75+
Branch.registerPlugin(BRANCH_PLUGIN_TYPE, BRANCH_PLUGIN_VERSION);
7776
if (this.instance == null) {
7877
this.instance = Branch.getAutoInstance(this.activity.getApplicationContext());
7978
}

src/ios/BranchSDK.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#import "BranchSDK.h"
22

3-
NSString * const pluginVersion = @"4.1.3";
3+
NSString * const pluginVersion = @"%BRANCH_PLUGIN_VERSION%";
44

55
@interface BranchSDK()
66

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
(function () {
2+
// properties
3+
4+
const setPluginVersion = require("../npm/setPluginVersion.js");
5+
const IOS = "ios";
6+
const ANDROID = "android";
7+
8+
// entry
9+
module.exports = run;
10+
11+
// runs before plugin installs
12+
function run(context) {
13+
const platforms = context.opts.cordova.platforms;
14+
15+
platforms.forEach(platform => {
16+
if (platform === IOS) {
17+
setPluginVersion.setIosPluginVersion(context);
18+
}
19+
20+
if (platform === ANDROID) {
21+
setPluginVersion.setAndroidPluginVersion(context);
22+
}
23+
});
24+
}
25+
})();

src/scripts/npm/setPluginVersion.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
(function() {
2+
// properties
3+
4+
const fs = require("fs");
5+
const path = require("path");
6+
7+
// entry
8+
module.exports = {
9+
setAndroidPluginVersion: setAndroidPluginVersion,
10+
setIosPluginVersion: setIosPluginVersion
11+
};
12+
13+
// set plugin version to BranchSDK.java
14+
function setAndroidPluginVersion(context) {
15+
const filePath = getAndroidSdkPath(context);
16+
updatePluginVersion(context, filePath);
17+
}
18+
19+
// set plugin version to BranchSDK.m
20+
function setIosPluginVersion(context) {
21+
const filePath = getIosSdkPath(context);
22+
updatePluginVersion(context, filePath);
23+
}
24+
25+
function getAndroidSdkPath(context) {
26+
return path.join(
27+
context.opts.projectRoot,
28+
'plugins',
29+
context.opts.plugin.pluginInfo.id,
30+
'src',
31+
'android',
32+
'io',
33+
'branch',
34+
'BranchSDK.java'
35+
);
36+
}
37+
38+
function getIosSdkPath(context) {
39+
return path.join(
40+
context.opts.projectRoot,
41+
'plugins',
42+
context.opts.plugin.pluginInfo.id,
43+
'src',
44+
'ios',
45+
'BranchSDK.m'
46+
);
47+
}
48+
49+
function updatePluginVersion(context, filePath) {
50+
let content = fs.readFileSync(filePath, "utf8");
51+
content = content.replace("%BRANCH_PLUGIN_VERSION%", context.opts.plugin.pluginInfo.version);
52+
fs.writeFileSync(filePath, content, "utf8");
53+
}
54+
})();

0 commit comments

Comments
 (0)