Skip to content

Commit e52f750

Browse files
authored
Merge pull request #294 from BranchMetrics/added-ios-and-android-bundle-id
feat: added ios and android bundle
2 parents b9c198a + 326d182 commit e52f750

File tree

10 files changed

+74
-47
lines changed

10 files changed

+74
-47
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,10 @@
597597
</branch-config>
598598
```
599599

600+
```xml
601+
<widget ios-CFBundleIdentifier="com.eneff.branch.cordovatestbedios" android-packageName="com.eneff.branch.cordovatestbedandroid" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
602+
```
603+
600604
- #### Testing: Sample Testing App
601605

602606
- [Branch Testing App](https://github.com/BranchMetrics/cordova-ionic-phonegap-branch-deep-linking/tree/master/testbed)

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "branch-cordova-sdk",
33
"description": "Branch Metrics Cordova SDK",
44
"main": "www/branch.js",
5-
"version": "2.5.3",
5+
"version": "2.5.5",
66
"homepage": "https://github.com/BranchMetrics/cordova-ionic-phonegap-branch-deep-linking",
77
"repository": {
88
"type": "git",
@@ -37,8 +37,9 @@
3737
},
3838
"scripts": {
3939
"commitmsg": "validate-commit-msg",
40+
"postcommit": "semantic-release pre --verifyRelease='./src/scripts/npm/nodeVersion'",
4041
"prerelease": "gulp prod",
41-
"semantic-release": "semantic-release pre --verifyRelease='./src/scripts/npm/nodeVersion' && npm publish && semantic-release post"
42+
"semantic-release": "semantic-release pre && npm publish && semantic-release post"
4243
},
4344
"dependencies": {
4445
"mkpath": "^1.0.0",
@@ -53,8 +54,8 @@
5354
"mkpath": "^1.0.0",
5455
"node-version-compare": "^1.0.1",
5556
"plist": "^1.2.0",
56-
"semantic-release": "^4.3.5",
57+
"semantic-release": "^6.3.6",
5758
"validate-commit-msg": "^2.8.2",
5859
"xml2js": "^0.4.17"
5960
}
60-
}
61+
}

plugin.template.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ SOFTWARE.
2424
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
2525
xmlns:android="http://schemas.android.com/apk/res/android"
2626
id="branch-cordova-sdk"
27-
version="2.5.3">
27+
version="2.5.5">
2828

2929
<!-- DO NOT EDIT THIS FILE. MAKE ALL CHANGES TO plugin.template.xml INSTEAD -->
3030

plugin.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ SOFTWARE.
2424
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
2525
xmlns:android="http://schemas.android.com/apk/res/android"
2626
id="branch-cordova-sdk"
27-
version="2.5.3">
27+
version="2.5.5">
2828

2929
<!-- DO NOT EDIT THIS FILE. MAKE ALL CHANGES TO plugin.template.xml INSTEAD -->
3030

src/branch.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ Branch.prototype.createBranchUniversalObject = function (options) {
153153
}
154154

155155
obj.listOnSpotlight = function () {
156-
if (deviceVendor.indexOf('Apple') < 0) {
156+
if (!(deviceVendor.indexOf('Apple') < 0)) {
157157
return execute('listOnSpotlight', [obj.instanceId])
158158
} else {
159159
return new Promise(function (resolve, reject) {

src/scripts/android/androidManifest.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
var metadatas = manifest['manifest']['application'][0]['meta-data'] || []
3636
var metadata = []
3737
var keys = ['io.branch.sdk.BranchKey', 'io.branch.sdk.TestMode']
38-
var vals = [preferences.branchKey, preferences.androidTestMode]
38+
var vals = [preferences.branchKey, preferences.androidTestMode || 'false']
3939

4040
// remove old
4141
for (var i = 0; i < keys.length; i++) {

src/scripts/ios/associatedDomains.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@
3030
// get the xcode .entitlements and provisioning profile .plist
3131
function getEntitlementFiles (preferences) {
3232
var files = []
33-
var entitlements = path.join(preferences.projectRoot, 'platforms', 'ios', preferences.bundleName, 'Resources', preferences.bundleName + '.entitlements')
33+
var entitlements = path.join(preferences.projectRoot, 'platforms', 'ios', preferences.projectName, 'Resources', preferences.projectName + '.entitlements')
3434
files.push(entitlements)
3535

3636
for (var i = 0; i < BUILD_TYPES.length; i++) {
3737
var buildType = BUILD_TYPES[i]
38-
var plist = path.join(preferences.projectRoot, 'platforms', 'ios', preferences.bundleName, 'Entitlements-' + buildType + '.plist')
38+
var plist = path.join(preferences.projectRoot, 'platforms', 'ios', preferences.projectName, 'Entitlements-' + buildType + '.plist')
3939
files.push(plist)
4040
}
4141

src/scripts/ios/capabilities.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
function enableAssociatedDomains (preferences) {
1616
console.log('BRANCH SDK: Updating iOS Xcode preferences')
1717

18-
var entitlementsFile = path.join(preferences.projectRoot, 'platforms', 'ios', preferences.bundleName, 'Resources', preferences.bundleName + '.entitlements')
19-
var projectFile = preferences.projectPlatform.parseProjectFile(path.join(preferences.projectRoot, 'platforms', 'ios'))
18+
var entitlementsFile = path.join(preferences.projectRoot, 'platforms', 'ios', preferences.projectName, 'Resources', preferences.projectName + '.entitlements')
19+
var projectFile = preferences.iosProjectModule.parseProjectFile(path.join(preferences.projectRoot, 'platforms', 'ios'))
2020

2121
activateAssociativeDomains(projectFile.xcode, entitlementsFile)
2222
addPbxReference(projectFile.xcode, entitlementsFile)

src/scripts/ios/plist.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
function addBranchSettings (preferences) {
1515
console.log('BRANCH SDK: Updating iOS info.plist')
1616

17-
var filePath = 'platforms/ios/' + preferences.bundleName + '/' + preferences.bundleName + '-Info.plist'
17+
var filePath = 'platforms/ios/' + preferences.projectName + '/' + preferences.projectName + '-Info.plist'
1818
var xml = readPlist(filePath)
1919
var obj = convertXmlToObject(xml)
2020

src/scripts/sdk/configXml.js

Lines changed: 56 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111

1212
// read branch config from config.xml
1313
function read (context) {
14-
var configXml = getConfigXml(context)
14+
var projectRoot = getProjectRoot(context)
15+
var configXml = getConfigXml(projectRoot)
1516
var branchXml = getBranchXml(configXml)
1617
var branchPreferences = getBranchPreferences(context, configXml, branchXml)
1718

@@ -21,8 +22,7 @@
2122
}
2223

2324
// read config.xml
24-
function getConfigXml (context) {
25-
var projectRoot = getProjectRoot(context)
25+
function getConfigXml (projectRoot) {
2626
var pathToConfigXml = path.join(projectRoot, 'config.xml')
2727
var configXml = xmlHelper.readXmlAsJson(pathToConfigXml)
2828

@@ -46,40 +46,53 @@
4646

4747
// read <branch-config> properties within config.xml
4848
function getBranchPreferences (context, configXml, branchXml) {
49-
var projectRoot = getProjectRoot(context)
50-
var projectPlatform = getProjectPlatform(context)
51-
var bundleId = (configXml.widget['$'].hasOwnProperty('id')) ? configXml.widget['$']['id'] : null
52-
var bundleName = (configXml.widget.hasOwnProperty('name')) ? configXml.widget.name[0] : null
53-
var branchKey = (branchXml.hasOwnProperty('branch-key')) ? branchXml['branch-key'][0]['$']['value'] : null
54-
var linkDomain = (branchXml.hasOwnProperty('link-domain')) ? branchXml['link-domain'][0]['$']['value'] : null
55-
var uriScheme = (branchXml.hasOwnProperty('uri-scheme')) ? branchXml['uri-scheme'][0]['$']['value'] : null
56-
var iosTeamRelease = (branchXml.hasOwnProperty('ios-team-release')) ? branchXml['ios-team-release'][0]['$']['value'] : null
57-
var iosTeamDebug = (branchXml.hasOwnProperty('ios-team-debug')) ? branchXml['ios-team-debug'][0]['$']['value'] : null
58-
var androidPrefix = (branchXml.hasOwnProperty('android-prefix')) ? branchXml['android-prefix'][0]['$']['value'] : null
59-
var androidTestMode = (branchXml.hasOwnProperty('android-testmode')) ? branchXml['android-testmode'][0]['$']['value'] : 'false'
60-
6149
return {
62-
'projectRoot': projectRoot,
63-
'projectPlatform': projectPlatform,
64-
'bundleId': bundleId,
65-
'bundleName': bundleName,
66-
'branchKey': branchKey,
67-
'uriScheme': uriScheme,
68-
'linkDomain': linkDomain,
69-
'iosTeamRelease': iosTeamRelease,
70-
'iosTeamDebug': iosTeamDebug, // optional
71-
'androidPrefix': androidPrefix, // optional
72-
'androidTestMode': androidTestMode // optional
50+
'projectRoot': getProjectRoot(context),
51+
'projectName': getProjectName(configXml),
52+
'branchKey': getBranchValue(branchXml, 'branch-key'),
53+
'linkDomain': getBranchValue(branchXml, 'link-domain'),
54+
'uriScheme': getBranchValue(branchXml, 'uri-scheme'),
55+
'iosBundleId': getBundleId(configXml, 'ios'),
56+
'iosProjectModule': getProjectModule(context),
57+
'iosTeamRelease': getBranchValue(branchXml, 'ios-team-release'),
58+
'iosTeamDebug': getBranchValue(branchXml, 'ios-team-debug'), // optional
59+
'androidBundleId': getBundleId(configXml, 'android'), // optional
60+
'androidPrefix': getBranchValue(branchXml, 'android-prefix'), // optional
61+
'androidTestMode': getBranchValue(branchXml, 'android-testmode') // optional
7362
}
7463
}
7564

76-
// read app project location
65+
// read project root from cordova context
7766
function getProjectRoot (context) {
78-
return context.opts.projectRoot
67+
return context.opts.projectRoot || null
68+
}
69+
70+
// read project name from config.xml
71+
function getProjectName (configXml) {
72+
return (configXml.widget.hasOwnProperty('name')) ? configXml.widget.name[0] : null
73+
}
74+
75+
// read branch value from <branch-config>
76+
function getBranchValue (branchXml, key) {
77+
return (branchXml.hasOwnProperty(key)) ? branchXml[key][0]['$']['value'] : null
7978
}
8079

81-
// read project platform
82-
function getProjectPlatform (context) {
80+
// read bundle id from config.xml (optional values override widget-id)
81+
function getBundleId (configXml, platform) {
82+
var output = null
83+
var key = platform === 'ios' ? 'ios-CFBundleIdentifier' : 'android-packageName'
84+
85+
if (configXml.widget['$'].hasOwnProperty(key)) {
86+
output = configXml.widget['$'][key]
87+
} else if (configXml.widget['$'].hasOwnProperty('id')) {
88+
output = configXml.widget['$']['id']
89+
}
90+
91+
return output
92+
}
93+
94+
// read iOS project module from cordova context
95+
function getProjectModule (context) {
8396
// try pre-5.0 cordova structure
8497
try {
8598
return context.requireCordovaModule('cordova-lib/src/plugman/platforms').ios
@@ -90,10 +103,13 @@
90103

91104
// validate <branch-config> properties within config.xml
92105
function validateBranchPreferences (preferences) {
93-
if (preferences.bundleId === null) {
94-
throw new Error('BRANCH SDK: Invalid "widget id" in your config.xml. Docs https://goo.gl/GijGKP')
106+
if (preferences.projectRoot === null) {
107+
throw new Error('BRANCH SDK: Invalid "root" in your config.xml. Docs https://goo.gl/GijGKP')
108+
}
109+
if (preferences.projectPlatform === null) {
110+
throw new Error('BRANCH SDK: Invalid "platform" in your config.xml. Docs https://goo.gl/GijGKP')
95111
}
96-
if (preferences.bundleName === null) {
112+
if (preferences.projectName === null) {
97113
throw new Error('BRANCH SDK: Invalid "name" in your config.xml. Docs https://goo.gl/GijGKP')
98114
}
99115
if (preferences.branchKey === null) {
@@ -105,16 +121,22 @@
105121
if (preferences.linkDomain === null || !/^(?!.*?www).*([a-zA-Z0-9]+(\.[a-zA-Z0-9]+)+.*)$/.test(preferences.linkDomain)) {
106122
throw new Error('BRANCH SDK: Invalid "link-domain" in <branch-config> in your config.xml. Docs https://goo.gl/GijGKP')
107123
}
124+
if (preferences.iosBundleId === null || !/^[a-zA-Z0-9.]*$/.test(preferences.iosBundleId)) {
125+
throw new Error('BRANCH SDK: Invalid "id" or "ios-CFBundleIdentifier" in <widget> in your config.xml. Docs https://goo.gl/GijGKP')
126+
}
108127
if (preferences.iosTeamRelease === null || !/^[a-zA-Z0-9]{10}$/.test(preferences.iosTeamRelease)) {
109128
throw new Error('BRANCH SDK: Invalid "ios-team-release" in <branch-config> in your config.xml. Docs https://goo.gl/GijGKP')
110129
}
111130
if (preferences.iosTeamDebug !== null && !/^[a-zA-Z0-9]{10}$/.test(preferences.iosTeamDebug)) {
112131
throw new Error('BRANCH SDK: Invalid "ios-team-debug" in <branch-config> in your config.xml. Docs https://goo.gl/GijGKP')
113132
}
133+
if (preferences.androidBundleId !== null && !/^[a-zA-Z0-9.]*$/.test(preferences.androidBundleId)) {
134+
throw new Error('BRANCH SDK: Invalid "id" or "android-packageName" in <widget> in your config.xml. Docs https://goo.gl/GijGKP')
135+
}
114136
if (preferences.androidPrefix !== null && !/^[/].[a-zA-Z0-9]{3}$/.test(preferences.androidPrefix)) {
115137
throw new Error('BRANCH SDK: Invalid "android-prefix" in <branch-config> in your config.xml. Docs https://goo.gl/GijGKP')
116138
}
117-
if (!(preferences.androidTestMode === 'true' || preferences.androidTestMode === 'false')) {
139+
if (!(preferences.androidTestMode === 'true' || preferences.androidTestMode === 'false' || preferences.androidTestMode === null)) {
118140
throw new Error('BRANCH SDK: Invalid "android-testmode" in <branch-config> in your config.xml. Docs https://goo.gl/GijGKP')
119141
}
120142
}

0 commit comments

Comments
 (0)