Skip to content

Commit

Permalink
fix: added support for iOS and Android bundle ids
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanneff committed Mar 7, 2017
1 parent ec5f7db commit f05ae30
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,10 @@
</branch-config>
```

```xml
<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">
```

- #### Testing: Sample Testing App

- [Branch Testing App](https://github.com/BranchMetrics/cordova-ionic-phonegap-branch-deep-linking/tree/master/testbed)
Expand Down
29 changes: 26 additions & 3 deletions src/scripts/sdk/configXml.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@

return {
'projectRoot': projectRoot,
'bundleId': bundleId,
'branchKey': branchKey,
'uriScheme': uriScheme,
'linkDomain': linkDomain,
Expand All @@ -69,7 +68,9 @@
'androidPrefix': androidPrefix, // optional
'androidTestMode': androidTestMode // optional
'projectName': getProjectName(configXml),
'iosBundleId': getBundleId(configXml, 'ios'),
'iosProjectModule': getProjectModule(context),
'androidBundleId': getBundleId(configXml, 'android'), // optional
}
}

Expand All @@ -80,6 +81,24 @@
function getProjectName (configXml) {
return (configXml.widget.hasOwnProperty('name')) ? configXml.widget.name[0] : null
}

// read branch value from <branch-config>
function getBranchValue (branchXml, key) {
return (branchXml.hasOwnProperty(key)) ? branchXml[key][0]['$']['value'] : null
}

// read bundle id from config.xml (optional values override widget-id)
function getBundleId (configXml, platform) {
var output = null
var key = platform === 'ios' ? 'ios-CFBundleIdentifier' : 'android-packageName'

if (configXml.widget['$'].hasOwnProperty(key)) {
output = configXml.widget['$'][key]
} else if (configXml.widget['$'].hasOwnProperty('id')) {
output = configXml.widget['$']['id']
}

return output
}

// read iOS project module from cordova context
Expand All @@ -94,8 +113,6 @@

// validate <branch-config> properties within config.xml
function validateBranchPreferences (preferences) {
if (preferences.bundleId === null) {
throw new Error('BRANCH SDK: Invalid "widget id" in your config.xml. Docs https://goo.gl/GijGKP')
}
if (preferences.projectName === null) {
throw new Error('BRANCH SDK: Invalid "name" in your config.xml. Docs https://goo.gl/GijGKP')
Expand All @@ -109,12 +126,18 @@
if (preferences.linkDomain === null || !/^(?!.*?www).*([a-zA-Z0-9]+(\.[a-zA-Z0-9]+)+.*)$/.test(preferences.linkDomain)) {
throw new Error('BRANCH SDK: Invalid "link-domain" in <branch-config> in your config.xml. Docs https://goo.gl/GijGKP')
}
if (preferences.iosBundleId === null || !/^[a-zA-Z0-9.]*$/.test(preferences.iosBundleId)) {
throw new Error('BRANCH SDK: Invalid "id" or "ios-CFBundleIdentifier" in <widget> in your config.xml. Docs https://goo.gl/GijGKP')
}
if (preferences.iosTeamRelease === null || !/^[a-zA-Z0-9]{10}$/.test(preferences.iosTeamRelease)) {
throw new Error('BRANCH SDK: Invalid "ios-team-release" in <branch-config> in your config.xml. Docs https://goo.gl/GijGKP')
}
if (preferences.iosTeamDebug !== null && !/^[a-zA-Z0-9]{10}$/.test(preferences.iosTeamDebug)) {
throw new Error('BRANCH SDK: Invalid "ios-team-debug" in <branch-config> in your config.xml. Docs https://goo.gl/GijGKP')
}
if (preferences.androidBundleId !== null && !/^[a-zA-Z0-9.]*$/.test(preferences.androidBundleId)) {
throw new Error('BRANCH SDK: Invalid "id" or "android-packageName" in <widget> in your config.xml. Docs https://goo.gl/GijGKP')
}
if (preferences.androidPrefix !== null && !/^[/].[a-zA-Z0-9]{3}$/.test(preferences.androidPrefix)) {
throw new Error('BRANCH SDK: Invalid "android-prefix" in <branch-config> in your config.xml. Docs https://goo.gl/GijGKP')
}
Expand Down

0 comments on commit f05ae30

Please sign in to comment.