From 8f338859fcb603c9da2e0236ca02bbe122a12393 Mon Sep 17 00:00:00 2001 From: Alvaro Date: Mon, 4 Sep 2017 12:24:47 +0200 Subject: [PATCH 1/4] Added iOS deeplinks entitlements hook --- README.md | 6 +++++ ios_deeplinks_entitlement.js | 46 ++++++++++++++++++++++++++++++++++++ package.json | 2 +- 3 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 ios_deeplinks_entitlement.js diff --git a/README.md b/README.md index 933c72c..7570d7c 100644 --- a/README.md +++ b/README.md @@ -133,6 +133,12 @@ recommended). If you want a hook to run before another one, reorder the `` * **function**: Adds `swift` support by adding universal objective c bridge to project. +##### `ios-deeplinks-entitlement.js` + +* **author**: [Nitsnets](http://www.nitsnets.com/) +* **usage**: `` +* **function**: When using `ionic-plugin-deeplinks` and iOS, adds the propper 'Associated Domains' entitlement to the XCode Project. +* **credit**: [@AlvYuste](https://github.com/AlvYuste/), [@ordas](https://github.com/ordas/) ### Contributing diff --git a/ios_deeplinks_entitlement.js b/ios_deeplinks_entitlement.js new file mode 100644 index 0000000..bc48877 --- /dev/null +++ b/ios_deeplinks_entitlement.js @@ -0,0 +1,46 @@ +#!/usr/bin/env node + +// deeplinks plugins generates entitlements in a way that isn't compatible +// with latest cordova build system, so we do it ourselves. +// +// https://github.com/ionic-team/ionic-plugin-deeplinks/issues/97 + +const fs = require('fs');[] +const plist = require('plist'); +const xmlParser = require('libxmljs'); + +const PlistKey = 'com.apple.developer.associated-domains'; + +module.exports = function (ctx) { + if (ctx.opts.platforms.indexOf('ios') < 0) { return; } + + const common = ctx.requireCordovaModule('cordova-common'); + const util = ctx.requireCordovaModule('cordova-lib/src/cordova/util'); + + const config = new common.ConfigParser(util.projectConfig(util.isCordova())); + const projectName = config.name(); + const paths = [ + `./platforms/ios/${projectName}/Entitlements-Debug.plist`, + `./platforms/ios/${projectName}/Entitlements-Release.plist` + ]; + const plugin = config.getPlugin('ionic-plugin-deeplinks'); + if (!plugin) { return; } + const domain = [`applinks:${plugin.variables.DEEPLINK_HOST}`]; + + paths.forEach(path => addEntitlementsToFile(path, domain)); +} + +function addEntitlementsToFile(path, domain) { + const origFileContent = fs.readFileSync(path, 'utf8'); + const parsedPlist = plist.parse(origFileContent); + + if (parsedPlist[PlistKey]) { + // give ourselves a chance to notice if/when the plugin gets fixed + // (though this might be too early) + console.warn('Entitlement already exists!', path, parsedPlist[PlistKey]); + } + parsedPlist[PlistKey] = domain; + + const newFileContent = plist.build(parsedPlist); + fs.writeFileSync(path, newFileContent, { encoding: 'utf8' }); +} diff --git a/package.json b/package.json index 266b331..fabf256 100644 --- a/package.json +++ b/package.json @@ -21,4 +21,4 @@ "xcode": "^0.8.2", "fs-extra": "3.0.1" } -} +} \ No newline at end of file From 814a34e9eef658a3ec79bc8f07a0a44593c975c5 Mon Sep 17 00:00:00 2001 From: Alvaro Yuste Torregrosa Date: Mon, 4 Sep 2017 13:28:38 +0200 Subject: [PATCH 2/4] Update ios_deeplinks_entitlement.js --- ios_deeplinks_entitlement.js | 1 + 1 file changed, 1 insertion(+) diff --git a/ios_deeplinks_entitlement.js b/ios_deeplinks_entitlement.js index bc48877..8a9ea21 100644 --- a/ios_deeplinks_entitlement.js +++ b/ios_deeplinks_entitlement.js @@ -44,3 +44,4 @@ function addEntitlementsToFile(path, domain) { const newFileContent = plist.build(parsedPlist); fs.writeFileSync(path, newFileContent, { encoding: 'utf8' }); } + From 77977f45b5cebf783db104e810e2b40bab18fb34 Mon Sep 17 00:00:00 2001 From: Alvaro Yuste Torregrosa Date: Mon, 4 Sep 2017 16:15:08 +0200 Subject: [PATCH 3/4] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7570d7c..8dfeee2 100644 --- a/README.md +++ b/README.md @@ -138,7 +138,7 @@ recommended). If you want a hook to run before another one, reorder the `` * **function**: When using `ionic-plugin-deeplinks` and iOS, adds the propper 'Associated Domains' entitlement to the XCode Project. -* **credit**: [@AlvYuste](https://github.com/AlvYuste/), [@ordas](https://github.com/ordas/) +* **credit**: [@AlvYuste](https://github.com/AlvYuste/), [@ordas](https://github.com/ordas/), [@lpg-mac](https://gist.github.com/lpg-mac) ### Contributing From 74143296e4215f6fbbe034228fba957b6a39d0a6 Mon Sep 17 00:00:00 2001 From: Alvaro Yuste Torregrosa Date: Mon, 4 Sep 2017 16:19:34 +0200 Subject: [PATCH 4/4] Update ios_deeplinks_entitlement.js --- ios_deeplinks_entitlement.js | 1 - 1 file changed, 1 deletion(-) diff --git a/ios_deeplinks_entitlement.js b/ios_deeplinks_entitlement.js index 8a9ea21..8d6320c 100644 --- a/ios_deeplinks_entitlement.js +++ b/ios_deeplinks_entitlement.js @@ -7,7 +7,6 @@ const fs = require('fs');[] const plist = require('plist'); -const xmlParser = require('libxmljs'); const PlistKey = 'com.apple.developer.associated-domains';