Skip to content
This repository was archived by the owner on Jul 20, 2018. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@ recommended). If you want a hook to run before another one, reorder the `<hook
* **usage**: `<hook type="after_platform_add" src="package-hooks/iosrtc-swift-support.js" />`
* **function**: Adds `swift` support by adding universal objective c bridge to project.

##### `ios-deeplinks-entitlement.js`

* **author**: [Nitsnets](http://www.nitsnets.com/)
* **usage**: `<hook type="after_prepare" src="package-hooks/ios_deeplinks_entitlement.js" />`
* **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/), [@lpg-mac](https://gist.github.com/lpg-mac)


### Contributing
Expand Down
46 changes: 46 additions & 0 deletions ios_deeplinks_entitlement.js
Original file line number Diff line number Diff line change
@@ -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 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' });
}

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@
"xcode": "^0.8.2",
"fs-extra": "3.0.1"
}
}
}