Skip to content

Commit

Permalink
fix: ShareExt.entitlements (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
shajz authored Sep 11, 2024
1 parent 7cd11bc commit 6a2c1f7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ cordova plugin add cc.fovea.cordova.openwith \
| `IOS_URL_SCHEME` | uniquelonglowercase | **iOS only** Any random long string of lowercase alphabetical characters |
| `IOS_UNIFORM_TYPE_IDENTIFIER` | public.image | **iOS only** UTI of documents you want to share, e.g. `public.image`, `public.movie`, `public.url`, `public.plain-text` or `public.item` for all UTIs (check [Apple's System-Declared UTI](https://developer.apple.com/library/content/documentation/Miscellaneous/Reference/UTIRef/Articles/System-DeclaredUniformTypeIdentifiers.html#//apple_ref/doc/uid/TP40009259-SW1)) |
| `IOS_GROUP_IDENTIFIER` | group.my.app.id | **iOS only** Custom app group name. Default is `group.<YOUR_APP_BUNDLE_ID>.shareextension`. |
| `SHAREEXT_PROVISIONING_PROFILE` | 9dfsdf-.... | **iOS only** UUID of provisioning profile for singing |
| `SHAREEXT_DEVELOPMENT_TEAM` | 00B000A09l | **iOS only** Developer account teamId |

It shouldn't be too hard. But just in case, I [posted a screencast of it](https://youtu.be/eaE4m_xO1mg).
Expand Down
19 changes: 11 additions & 8 deletions hooks/iosAddTarget.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function arrayFilterUnique(value, index, self) {

function addEntitlments(filePath, preferences) {
var plist = require('plist');
var plistContent = plist.parse(fs.readFileSync(filePath, 'utf8'));
var plistContent = fs.existsSync(filePath) ? plist.parse(fs.readFileSync(filePath, 'utf8')) : {};
var parent = 'com.apple.security.application-groups';
for (var i = 0; i < preferences.length; i++) {
var pref = preferences[i];
Expand Down Expand Up @@ -341,23 +341,26 @@ module.exports = function (context) {
// Add App Group to entitlments
addEntitlments(path.join(iosFolder(context), projectName, 'Entitlements-Debug.plist'), preferences);
addEntitlments(path.join(iosFolder(context), projectName, 'Entitlements-Release.plist'), preferences);
// ShareExt.entitlments is needed and must be linked to root project
addEntitlments(path.join(iosFolder(context), 'ShareExt.entitlements'), preferences);
var customTemplateKey = pbxProject.findPBXGroupKey({name: 'CustomTemplate'});
pbxProject.addFile('ShareExt.entitlements', customTemplateKey, { lastKnownFileType: 'text.plist.entitlements' });

//Add development team and provisioning profile
var PROVISIONING_PROFILE = getCordovaParameter(configXml, 'SHAREEXT_PROVISIONING_PROFILE');
// Add development team
var DEVELOPMENT_TEAM = getCordovaParameter(configXml, 'SHAREEXT_DEVELOPMENT_TEAM');
console.log('Adding team', DEVELOPMENT_TEAM, 'and provisoning profile', PROVISIONING_PROFILE);
if (PROVISIONING_PROFILE && DEVELOPMENT_TEAM) {
console.log('Adding team', DEVELOPMENT_TEAM);
if (DEVELOPMENT_TEAM) {
var configurations = pbxProject.pbxXCBuildConfigurationSection();
for (var key in configurations) {
if (typeof configurations[key].buildSettings !== 'undefined') {
var buildSettingsObj = configurations[key].buildSettings;
if (typeof buildSettingsObj['PRODUCT_NAME'] !== 'undefined') {
var productName = buildSettingsObj['PRODUCT_NAME'];
if (productName.indexOf('ShareExt') >= 0) {
buildSettingsObj['PROVISIONING_PROFILE'] = PROVISIONING_PROFILE;
buildSettingsObj['DEVELOPMENT_TEAM'] = DEVELOPMENT_TEAM;
buildSettingsObj['CODE_SIGN_STYLE'] = 'Manual';
buildSettingsObj['CODE_SIGN_IDENTITY'] = '"iPhone Distribution"';
buildSettingsObj['CODE_SIGN_STYLE'] = 'Automatic';
buildSettingsObj['CODE_SIGN_IDENTITY'] = '"Apple Development"';
buildSettingsObj['CODE_SIGN_ENTITLEMENTS'] = 'ShareExt.entitlements';
console.log('Added signing identities for extension!');
}
}
Expand Down

0 comments on commit 6a2c1f7

Please sign in to comment.