Skip to content

Commit

Permalink
✨ Set group entitlements in hook
Browse files Browse the repository at this point in the history
  • Loading branch information
dertieran committed Dec 20, 2019
1 parent 236d711 commit 45c70f2
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 15 deletions.
32 changes: 31 additions & 1 deletion hooks/ios/add-target.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@ const getPreferences = function(context, configXML, projectName) {
});
};

const setGroupEntitlement = function (file, group) {
const entitlement = 'com.apple.security.application-groups';
return readFile(file, 'utf-8').then(xml => {
const parsed = plist.parse(xml);
parsed[entitlement] = [group];
return writeFile(file, plist.build(parsed));
});
};

module.exports = function(context) {
console.log('Adding target "' + PLUGIN_ID + '/ShareExtension" to XCode project');

Expand Down Expand Up @@ -188,7 +197,28 @@ module.exports = function(context) {
return writeFile(pbx.path, pbx.project.writeSync());
});

return Promise.all([replacedPreferences, updatedPbxProject]).then(() =>
const setGroupEntitlements = Promise.all([
resolvedXCodeProject,
resolvedPreferences
]).then(([project, preferences]) => {
const dir = path.join(getPlatformFolder(context), project.name);
const group = preferences.find(
preference => preference.key === '__GROUP_IDENTIFIER__'
);
return Promise.all([
setGroupEntitlement(
path.join(dir, 'Entitlements-Debug.plist'),
group.value
),
setGroupEntitlement(
path.join(dir, 'Entitlements-Release.plist'),
group.value
)
]);
});


return Promise.all([replacedPreferences, updatedPbxProject, setGroupEntitlements]).then(() =>
console.log('Added ShareExtension to XCode project')
);
};
14 changes: 0 additions & 14 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,6 @@
</array>
</config-file>

<!-- Entitlements (Debug) -->
<config-file target="*-Debug.plist" parent="com.apple.security.application-groups">
<array>
<string>group.$(CFBundleIdentifier).shareextension</string>
</array>
</config-file>

<!-- Entitlements (Release) -->
<config-file target="*-Release.plist" parent="com.apple.security.application-groups">
<array>
<string>group.$(CFBundleIdentifier).shareextension</string>
</array>
</config-file>

<source-file src="src/ios/OpenWithPlugin.m"/>

<!-- Cordova hooks -->
Expand Down

0 comments on commit 45c70f2

Please sign in to comment.