Skip to content

Commit

Permalink
Merge pull request #294 from BranchMetrics/added-ios-and-android-bund…
Browse files Browse the repository at this point in the history
…le-id

feat: added ios and android bundle
  • Loading branch information
ethanneff authored Mar 7, 2017
2 parents b9c198a + 326d182 commit e52f750
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 47 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
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "branch-cordova-sdk",
"description": "Branch Metrics Cordova SDK",
"main": "www/branch.js",
"version": "2.5.3",
"version": "2.5.5",
"homepage": "https://github.com/BranchMetrics/cordova-ionic-phonegap-branch-deep-linking",
"repository": {
"type": "git",
Expand Down Expand Up @@ -37,8 +37,9 @@
},
"scripts": {
"commitmsg": "validate-commit-msg",
"postcommit": "semantic-release pre --verifyRelease='./src/scripts/npm/nodeVersion'",
"prerelease": "gulp prod",
"semantic-release": "semantic-release pre --verifyRelease='./src/scripts/npm/nodeVersion' && npm publish && semantic-release post"
"semantic-release": "semantic-release pre && npm publish && semantic-release post"
},
"dependencies": {
"mkpath": "^1.0.0",
Expand All @@ -53,8 +54,8 @@
"mkpath": "^1.0.0",
"node-version-compare": "^1.0.1",
"plist": "^1.2.0",
"semantic-release": "^4.3.5",
"semantic-release": "^6.3.6",
"validate-commit-msg": "^2.8.2",
"xml2js": "^0.4.17"
}
}
}
2 changes: 1 addition & 1 deletion plugin.template.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ SOFTWARE.
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="branch-cordova-sdk"
version="2.5.3">
version="2.5.5">

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

Expand Down
2 changes: 1 addition & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ SOFTWARE.
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="branch-cordova-sdk"
version="2.5.3">
version="2.5.5">

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

Expand Down
2 changes: 1 addition & 1 deletion src/branch.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ Branch.prototype.createBranchUniversalObject = function (options) {
}

obj.listOnSpotlight = function () {
if (deviceVendor.indexOf('Apple') < 0) {
if (!(deviceVendor.indexOf('Apple') < 0)) {
return execute('listOnSpotlight', [obj.instanceId])
} else {
return new Promise(function (resolve, reject) {
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/android/androidManifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
var metadatas = manifest['manifest']['application'][0]['meta-data'] || []
var metadata = []
var keys = ['io.branch.sdk.BranchKey', 'io.branch.sdk.TestMode']
var vals = [preferences.branchKey, preferences.androidTestMode]
var vals = [preferences.branchKey, preferences.androidTestMode || 'false']

// remove old
for (var i = 0; i < keys.length; i++) {
Expand Down
4 changes: 2 additions & 2 deletions src/scripts/ios/associatedDomains.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@
// get the xcode .entitlements and provisioning profile .plist
function getEntitlementFiles (preferences) {
var files = []
var entitlements = path.join(preferences.projectRoot, 'platforms', 'ios', preferences.bundleName, 'Resources', preferences.bundleName + '.entitlements')
var entitlements = path.join(preferences.projectRoot, 'platforms', 'ios', preferences.projectName, 'Resources', preferences.projectName + '.entitlements')
files.push(entitlements)

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

Expand Down
4 changes: 2 additions & 2 deletions src/scripts/ios/capabilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
function enableAssociatedDomains (preferences) {
console.log('BRANCH SDK: Updating iOS Xcode preferences')

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

activateAssociativeDomains(projectFile.xcode, entitlementsFile)
addPbxReference(projectFile.xcode, entitlementsFile)
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/ios/plist.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
function addBranchSettings (preferences) {
console.log('BRANCH SDK: Updating iOS info.plist')

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

Expand Down
90 changes: 56 additions & 34 deletions src/scripts/sdk/configXml.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@

// read branch config from config.xml
function read (context) {
var configXml = getConfigXml(context)
var projectRoot = getProjectRoot(context)
var configXml = getConfigXml(projectRoot)
var branchXml = getBranchXml(configXml)
var branchPreferences = getBranchPreferences(context, configXml, branchXml)

Expand All @@ -21,8 +22,7 @@
}

// read config.xml
function getConfigXml (context) {
var projectRoot = getProjectRoot(context)
function getConfigXml (projectRoot) {
var pathToConfigXml = path.join(projectRoot, 'config.xml')
var configXml = xmlHelper.readXmlAsJson(pathToConfigXml)

Expand All @@ -46,40 +46,53 @@

// read <branch-config> properties within config.xml
function getBranchPreferences (context, configXml, branchXml) {
var projectRoot = getProjectRoot(context)
var projectPlatform = getProjectPlatform(context)
var bundleId = (configXml.widget['$'].hasOwnProperty('id')) ? configXml.widget['$']['id'] : null
var bundleName = (configXml.widget.hasOwnProperty('name')) ? configXml.widget.name[0] : null
var branchKey = (branchXml.hasOwnProperty('branch-key')) ? branchXml['branch-key'][0]['$']['value'] : null
var linkDomain = (branchXml.hasOwnProperty('link-domain')) ? branchXml['link-domain'][0]['$']['value'] : null
var uriScheme = (branchXml.hasOwnProperty('uri-scheme')) ? branchXml['uri-scheme'][0]['$']['value'] : null
var iosTeamRelease = (branchXml.hasOwnProperty('ios-team-release')) ? branchXml['ios-team-release'][0]['$']['value'] : null
var iosTeamDebug = (branchXml.hasOwnProperty('ios-team-debug')) ? branchXml['ios-team-debug'][0]['$']['value'] : null
var androidPrefix = (branchXml.hasOwnProperty('android-prefix')) ? branchXml['android-prefix'][0]['$']['value'] : null
var androidTestMode = (branchXml.hasOwnProperty('android-testmode')) ? branchXml['android-testmode'][0]['$']['value'] : 'false'

return {
'projectRoot': projectRoot,
'projectPlatform': projectPlatform,
'bundleId': bundleId,
'bundleName': bundleName,
'branchKey': branchKey,
'uriScheme': uriScheme,
'linkDomain': linkDomain,
'iosTeamRelease': iosTeamRelease,
'iosTeamDebug': iosTeamDebug, // optional
'androidPrefix': androidPrefix, // optional
'androidTestMode': androidTestMode // optional
'projectRoot': getProjectRoot(context),
'projectName': getProjectName(configXml),
'branchKey': getBranchValue(branchXml, 'branch-key'),
'linkDomain': getBranchValue(branchXml, 'link-domain'),
'uriScheme': getBranchValue(branchXml, 'uri-scheme'),
'iosBundleId': getBundleId(configXml, 'ios'),
'iosProjectModule': getProjectModule(context),
'iosTeamRelease': getBranchValue(branchXml, 'ios-team-release'),
'iosTeamDebug': getBranchValue(branchXml, 'ios-team-debug'), // optional
'androidBundleId': getBundleId(configXml, 'android'), // optional
'androidPrefix': getBranchValue(branchXml, 'android-prefix'), // optional
'androidTestMode': getBranchValue(branchXml, 'android-testmode') // optional
}
}

// read app project location
// read project root from cordova context
function getProjectRoot (context) {
return context.opts.projectRoot
return context.opts.projectRoot || null
}

// read project name from config.xml
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 project platform
function getProjectPlatform (context) {
// 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
function getProjectModule (context) {
// try pre-5.0 cordova structure
try {
return context.requireCordovaModule('cordova-lib/src/plugman/platforms').ios
Expand All @@ -90,10 +103,13 @@

// 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.projectRoot === null) {
throw new Error('BRANCH SDK: Invalid "root" in your config.xml. Docs https://goo.gl/GijGKP')
}
if (preferences.projectPlatform === null) {
throw new Error('BRANCH SDK: Invalid "platform" in your config.xml. Docs https://goo.gl/GijGKP')
}
if (preferences.bundleName === null) {
if (preferences.projectName === null) {
throw new Error('BRANCH SDK: Invalid "name" in your config.xml. Docs https://goo.gl/GijGKP')
}
if (preferences.branchKey === null) {
Expand All @@ -105,16 +121,22 @@
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')
}
if (!(preferences.androidTestMode === 'true' || preferences.androidTestMode === 'false')) {
if (!(preferences.androidTestMode === 'true' || preferences.androidTestMode === 'false' || preferences.androidTestMode === null)) {
throw new Error('BRANCH SDK: Invalid "android-testmode" in <branch-config> in your config.xml. Docs https://goo.gl/GijGKP')
}
}
Expand Down

0 comments on commit e52f750

Please sign in to comment.