From 3347e917eef415867c6fb6bc903ee837c7c09365 Mon Sep 17 00:00:00 2001 From: Niklas Merz Date: Thu, 5 Sep 2019 09:21:41 +0200 Subject: [PATCH 01/17] Set version in plugin.xml --- plugin.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin.xml b/plugin.xml index 96ffbd9..f1b2f95 100644 --- a/plugin.xml +++ b/plugin.xml @@ -26,7 +26,7 @@ SOFTWARE. + version="1.3.0"> OpenWith Cordova "Open With" plugin for iOS and Android From c301c518f49b5aef77538fc2e290ea7bd55372f5 Mon Sep 17 00:00:00 2001 From: Niklas Merz Date: Thu, 5 Sep 2019 09:23:20 +0200 Subject: [PATCH 02/17] 1.3.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b40476d..72e6be9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cc.fovea.cordova.openwith", - "version": "1.2.0", + "version": "1.3.0", "description": "Cordova \"Open With\" plugin for iOS and Android", "cordova": { "id": "cc.fovea.cordova.openwith", From a9143178707a2f243515bc2b8474b79d691e07ad Mon Sep 17 00:00:00 2001 From: Niklas Merz Date: Tue, 31 Dec 2019 11:49:20 +0100 Subject: [PATCH 03/17] Fix extension crash on iOS 13 (#69) * Fix extension crash on iOS 13 * Fix UISceneOpenExternalURLOptions init * iOS 13 version check --- src/ios/ShareExtension/ShareViewController.m | 31 ++++++++++++++------ 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/src/ios/ShareExtension/ShareViewController.m b/src/ios/ShareExtension/ShareViewController.m index 409a0f3..3fc2d75 100644 --- a/src/ios/ShareExtension/ShareViewController.m +++ b/src/ios/ShareExtension/ShareViewController.m @@ -88,18 +88,31 @@ - (void) openURL:(nonnull NSURL *)url { NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:methodSignature]; // Arguments - NSDictionary *options = [NSDictionary dictionary]; void (^completion)(BOOL success) = ^void(BOOL success) { NSLog(@"Completions block: %i", success); }; - - [invocation setTarget: responder]; - [invocation setSelector: selector]; - [invocation setArgument: &url atIndex: 2]; - [invocation setArgument: &options atIndex:3]; - [invocation setArgument: &completion atIndex: 4]; - [invocation invoke]; - break; + if (@available(iOS 13.0, *)) { + UISceneOpenExternalURLOptions * options = [[UISceneOpenExternalURLOptions alloc] init]; + options.universalLinksOnly = false; + + [invocation setTarget: responder]; + [invocation setSelector: selector]; + [invocation setArgument: &url atIndex: 2]; + [invocation setArgument: &options atIndex:3]; + [invocation setArgument: &completion atIndex: 4]; + [invocation invoke]; + break; + } else { + NSDictionary *options = [NSDictionary dictionary]; + + [invocation setTarget: responder]; + [invocation setSelector: selector]; + [invocation setArgument: &url atIndex: 2]; + [invocation setArgument: &options atIndex:3]; + [invocation setArgument: &completion atIndex: 4]; + [invocation invoke]; + break; + } } } } From cafd3617585c0c93da32edc61419369f1976d1c4 Mon Sep 17 00:00:00 2001 From: Niklas Merz Date: Tue, 31 Dec 2019 11:51:33 +0100 Subject: [PATCH 04/17] Fix iOS build flags (#84) --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index acb3e5e..16aaedf 100644 --- a/README.md +++ b/README.md @@ -66,8 +66,8 @@ 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 (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..shareextension`. | -| `SHAREEXT_PROVISIONING_PROFILE` | 9dfsdf-.... | **iOS only** Developer account teamId | -| `SHAREEXT_DEVELOPMENT_TEAM` | 00B000A09l | **iOS only** UUID of provisioning profile for singing | +| `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). From 7920363b93fb0f7868ff6f9f092ca687852e74a0 Mon Sep 17 00:00:00 2001 From: devtobo Date: Wed, 1 Jan 2020 11:51:40 -0500 Subject: [PATCH 05/17] change hook triggering iosAddTarget.js. Fixes the target not being added to xcode project. (#72) --- plugin.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin.xml b/plugin.xml index f1b2f95..63515ab 100644 --- a/plugin.xml +++ b/plugin.xml @@ -76,7 +76,7 @@ SOFTWARE. - + From 5ef2fe7b9b5227767cf80319373e4c43a8c44275 Mon Sep 17 00:00:00 2001 From: Niklas Merz Date: Wed, 1 Jan 2020 18:02:05 +0100 Subject: [PATCH 06/17] Bump version 2.0.0 --- plugin.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin.xml b/plugin.xml index 63515ab..6e7e617 100644 --- a/plugin.xml +++ b/plugin.xml @@ -26,7 +26,7 @@ SOFTWARE. + version="2.0.0"> OpenWith Cordova "Open With" plugin for iOS and Android From 262c1676d443239bf408dc89f2598d5c15a9488a Mon Sep 17 00:00:00 2001 From: Niklas Merz Date: Wed, 1 Jan 2020 18:03:18 +0100 Subject: [PATCH 07/17] 2.0.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 72e6be9..8d38604 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cc.fovea.cordova.openwith", - "version": "1.3.0", + "version": "2.0.0", "description": "Cordova \"Open With\" plugin for iOS and Android", "cordova": { "id": "cc.fovea.cordova.openwith", From e5e4fb8e79128b8fccd6a85c8b67c2c278310bd6 Mon Sep 17 00:00:00 2001 From: BenjaminPoncet Date: Sun, 1 Mar 2020 14:22:23 +0100 Subject: [PATCH 08/17] IOS : Move hooks on before and after prepare This allows ShareExtension to be created and updated in any case --- plugin.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin.xml b/plugin.xml index 6e7e617..0b538e1 100644 --- a/plugin.xml +++ b/plugin.xml @@ -75,8 +75,8 @@ SOFTWARE. - - + + From 978ce0088f7af9c72ff846ad0ad574ddf757f404 Mon Sep 17 00:00:00 2001 From: BenjaminPoncet Date: Sun, 1 Mar 2020 17:52:04 +0100 Subject: [PATCH 09/17] IOS : Fix getCordovaParameter() to use package.json Because after_prepare hook does not pass installation variables in process.argv --- hooks/iosAddTarget.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/hooks/iosAddTarget.js b/hooks/iosAddTarget.js index cd8e204..c6ae1cf 100755 --- a/hooks/iosAddTarget.js +++ b/hooks/iosAddTarget.js @@ -34,6 +34,7 @@ const BUNDLE_SUFFIX = '.shareextension'; var fs = require('fs'); var path = require('path'); +var packageJson; function redError(message) { return new Error('"' + PLUGIN_ID + '" \x1b[1m\x1b[31m' + message + '\x1b[0m'); @@ -93,13 +94,8 @@ function getPreferenceValue(configXml, name) { } function getCordovaParameter(configXml, variableName) { - var variable; - var arg = process.argv.filter(function(arg) { - return arg.indexOf(variableName + '=') == 0; - }); - if (arg.length >= 1) { - variable = arg[0].split('=')[1]; - } else { + var variable = packageJson.cordova.plugins[PLUGIN_ID][variableName]; + if (!variable) { variable = getPreferenceValue(configXml, variableName); } return variable; @@ -215,6 +211,8 @@ module.exports = function (context) { var Q = require('q'); var deferral = new Q.defer(); + packageJson = require(path.join(context.opts.projectRoot, 'package.json')); + // if (context.opts.cordova.platforms.indexOf('ios') < 0) { // log('You have to add the ios platform before adding this plugin!', 'error'); // } @@ -249,7 +247,7 @@ module.exports = function (context) { if (!target) { // Add PBXNativeTarget to the project target = pbxProject.addTarget('ShareExt', 'app_extension', 'ShareExtension'); - + // Add a new PBXSourcesBuildPhase for our ShareViewController // (we can't add it to the existing one because an extension is kind of an extra app) pbxProject.addBuildPhase([], 'PBXSourcesBuildPhase', 'Sources', target.uuid); From 1aa2de422232ce7b601c899bedb731a98cbccc64 Mon Sep 17 00:00:00 2001 From: BenjaminPoncet Date: Sun, 1 Mar 2020 18:02:13 +0100 Subject: [PATCH 10/17] IOS : Fix App Group creation and fix Share Extension Bundle Identifier --- hooks/iosAddTarget.js | 35 ++++++++++++++----- .../ShareExtension-Entitlements.plist | 10 ++++++ 2 files changed, 36 insertions(+), 9 deletions(-) create mode 100644 src/ios/ShareExtension/ShareExtension-Entitlements.plist diff --git a/hooks/iosAddTarget.js b/hooks/iosAddTarget.js index c6ae1cf..13bf1f2 100755 --- a/hooks/iosAddTarget.js +++ b/hooks/iosAddTarget.js @@ -35,6 +35,7 @@ const BUNDLE_SUFFIX = '.shareextension'; var fs = require('fs'); var path = require('path'); var packageJson; +var bundleIdentifier; function redError(message) { return new Error('"' + PLUGIN_ID + '" \x1b[1m\x1b[31m' + message + '\x1b[0m'); @@ -102,11 +103,11 @@ function getCordovaParameter(configXml, variableName) { } // Get the bundle id from config.xml -// function getBundleId(context, configXml) { -// var elementTree = require('elementtree'); -// var etree = elementTree.parse(configXml); -// return etree.getroot().get('id'); -// } +function getBundleId(context, configXml) { + var elementTree = require('elementtree'); + var etree = elementTree.parse(configXml); + return etree.getroot().get('id'); +} function parsePbxProject(context, pbxProjectPath) { var xcode = require('xcode'); @@ -147,8 +148,8 @@ function projectPlistJson(context, projectName) { function getPreferences(context, configXml, projectName) { var plist = projectPlistJson(context, projectName); - var group = "group." + plist.CFBundleIdentifier + BUNDLE_SUFFIX; - if (getCordovaParameter(configXml, 'GROUP_IDENTIFIER') !== "") { + var group = "group." + bundleIdentifier + BUNDLE_SUFFIX; + if (getCordovaParameter(configXml, 'IOS_GROUP_IDENTIFIER')) { group = getCordovaParameter(configXml, 'IOS_GROUP_IDENTIFIER'); } return [{ @@ -222,6 +223,8 @@ module.exports = function (context) { configXml = configXml.substring(configXml.indexOf('<')); } + bundleIdentifier = getBundleId(context, configXml); + findXCodeproject(context, function(projectFolder, projectName) { console.log(' - Folder containing your iOS project: ' + iosFolder(context)); @@ -239,7 +242,7 @@ module.exports = function (context) { }); // Find if the project already contains the target and group - var target = pbxProject.pbxTargetByName('ShareExt'); + var target = pbxProject.pbxTargetByName('ShareExt') || pbxProject.pbxTargetByName('"ShareExt"'); if (target) { console.log(' ShareExt target already exists.'); } @@ -259,7 +262,7 @@ module.exports = function (context) { // Create a separate PBXGroup for the shareExtensions files, name has to be unique and path must be in quotation marks var pbxGroupKey = pbxProject.findPBXGroupKey({name: 'ShareExtension'}); - if (pbxProject) { + if (pbxGroupKey) { console.log(' ShareExtension group already exists.'); } if (!pbxGroupKey) { @@ -285,6 +288,20 @@ module.exports = function (context) { pbxProject.addResourceFile(file.name, {target: target.uuid}, pbxGroupKey); }); + 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') { + buildSettingsObj['CODE_SIGN_ENTITLEMENTS'] = '"ShareExtension/ShareExtension-Entitlements.plist"'; + var productName = buildSettingsObj['PRODUCT_NAME']; + if (productName.indexOf('ShareExt') >= 0) { + buildSettingsObj['PRODUCT_BUNDLE_IDENTIFIER'] = bundleIdentifier+BUNDLE_SUFFIX; + } + } + } + } + //Add development team and provisioning profile var PROVISIONING_PROFILE = getCordovaParameter(configXml, 'SHAREEXT_PROVISIONING_PROFILE'); var DEVELOPMENT_TEAM = getCordovaParameter(configXml, 'SHAREEXT_DEVELOPMENT_TEAM'); diff --git a/src/ios/ShareExtension/ShareExtension-Entitlements.plist b/src/ios/ShareExtension/ShareExtension-Entitlements.plist new file mode 100644 index 0000000..93e1fc7 --- /dev/null +++ b/src/ios/ShareExtension/ShareExtension-Entitlements.plist @@ -0,0 +1,10 @@ + + + + + com.apple.security.application-groups + + __GROUP_IDENTIFIER__ + + + From 5e0d7a6c0a8d9c9efde41c5b806068da1fcce705 Mon Sep 17 00:00:00 2001 From: Benjamin Poncet <47477730+BenjaminPoncet@users.noreply.github.com> Date: Mon, 2 Mar 2020 14:34:36 +0100 Subject: [PATCH 11/17] IOS : Remove "iOS Setup" section Because everything is now automatic --- README.md | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/README.md b/README.md index 16aaedf..a077c98 100644 --- a/README.md +++ b/README.md @@ -71,23 +71,6 @@ cordova plugin add cc.fovea.cordova.openwith \ It shouldn't be too hard. But just in case, I [posted a screencast of it](https://youtu.be/eaE4m_xO1mg). -### iOS Setup - -After having installed the plugin, with the ios platform in place, 1 operation needs to be done manually: setup the App Group on both the Cordova App and the Share Extension. - - 1. open the **xcodeproject** for your application - 1. select the root element of your **project navigator** (the left-side pane) - 1. select the **target** of your application - 1. select **capabilities** - 1. scroll down to **App Groups** - 1. make sure it's **ON** - 1. create and activate an **App Group** called: `group..shareextension` - 1. repeat the previous five steps for the **ShareExtension target**. - -You might also have to select a Team for both the App and Share Extension targets, make sure to select the same. - -Build, XCode might complain about a few things to setup that it will fix for you (creation entitlements files, etc). - ### Advanced installation options If you do not need anything fancy, you can skip this section. From a3e2d18ae7241ab385ef4b71e4f51ec36a95baf0 Mon Sep 17 00:00:00 2001 From: BenjaminPoncet Date: Thu, 5 Mar 2020 11:48:21 +0100 Subject: [PATCH 12/17] IOS : Add ShareExtension-Entitlements.plist to package.json --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 8d38604..1059368 100644 --- a/package.json +++ b/package.json @@ -67,6 +67,7 @@ "src/android/cc/fovea/openwith/Serializer.java", "src/ios/OpenWithPlugin.m", "src/ios/ShareExtension/MainInterface.storyboard", + "src/ios/ShareExtension/ShareExtension-Entitlements.plist", "src/ios/ShareExtension/ShareExtension-Info.plist", "src/ios/ShareExtension/ShareViewController.h", "src/ios/ShareExtension/ShareViewController.m", From 05e6caf4bb52b0810d69ea128312b492fae92cf9 Mon Sep 17 00:00:00 2001 From: BenjaminPoncet Date: Thu, 5 Mar 2020 14:37:29 +0100 Subject: [PATCH 13/17] IOS : Fix __BUNDLE_IDENTIFIER__ to prevent double suffix --- hooks/iosAddTarget.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hooks/iosAddTarget.js b/hooks/iosAddTarget.js index 13bf1f2..191f4fc 100755 --- a/hooks/iosAddTarget.js +++ b/hooks/iosAddTarget.js @@ -157,7 +157,7 @@ function getPreferences(context, configXml, projectName) { value: projectName }, { key: '__BUNDLE_IDENTIFIER__', - value: plist.CFBundleIdentifier + BUNDLE_SUFFIX + value: bundleIdentifier + BUNDLE_SUFFIX } ,{ key: '__GROUP_IDENTIFIER__', value: group From e22dd968d7981f862cbb80452115aba20da823cc Mon Sep 17 00:00:00 2001 From: Harel Mazor Date: Thu, 23 Jul 2020 21:28:17 +0300 Subject: [PATCH 14/17] Added a copy files to after install hook --- hooks/iosAddTarget.js | 4 ++++ plugin.xml | 1 + 2 files changed, 5 insertions(+) diff --git a/hooks/iosAddTarget.js b/hooks/iosAddTarget.js index 191f4fc..295a08f 100755 --- a/hooks/iosAddTarget.js +++ b/hooks/iosAddTarget.js @@ -124,6 +124,10 @@ function parsePbxProject(context, pbxProjectPath) { function forEachShareExtensionFile(context, callback) { var shareExtensionFolder = path.join(iosFolder(context), 'ShareExtension'); + if (!fs.exists(shareExtensionFolder)) { + console.error('!! Shared extension files have not been copied yet!!'); + return; + } fs.readdirSync(shareExtensionFolder).forEach(function(name) { // Ignore junk files like .DS_Store if (!/^\..*/.test(name)) { diff --git a/plugin.xml b/plugin.xml index 0b538e1..29072b5 100644 --- a/plugin.xml +++ b/plugin.xml @@ -75,6 +75,7 @@ SOFTWARE. + From a47f397111b6de5cf28a5ede857b2d811e6376d8 Mon Sep 17 00:00:00 2001 From: Harel Mazor Date: Thu, 23 Jul 2020 21:43:50 +0300 Subject: [PATCH 15/17] Fix async call --- hooks/iosAddTarget.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hooks/iosAddTarget.js b/hooks/iosAddTarget.js index 295a08f..dfb095c 100755 --- a/hooks/iosAddTarget.js +++ b/hooks/iosAddTarget.js @@ -124,7 +124,7 @@ function parsePbxProject(context, pbxProjectPath) { function forEachShareExtensionFile(context, callback) { var shareExtensionFolder = path.join(iosFolder(context), 'ShareExtension'); - if (!fs.exists(shareExtensionFolder)) { + if (!fs.existsSync(shareExtensionFolder)) { console.error('!! Shared extension files have not been copied yet!!'); return; } From 7d6fa27554bb1980d3985f097462963071962701 Mon Sep 17 00:00:00 2001 From: Harel Mazor Date: Sun, 26 Jul 2020 10:40:26 +0300 Subject: [PATCH 16/17] Change code sign indentity and style --- hooks/iosAddTarget.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hooks/iosAddTarget.js b/hooks/iosAddTarget.js index dfb095c..f721547 100755 --- a/hooks/iosAddTarget.js +++ b/hooks/iosAddTarget.js @@ -320,6 +320,8 @@ module.exports = function (context) { 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'; console.log('Added signing identities for extension!'); } } From bb167ed427b59215407fd4ce7296e5a669a4f762 Mon Sep 17 00:00:00 2001 From: Harel Mazor Date: Sun, 26 Jul 2020 10:55:38 +0300 Subject: [PATCH 17/17] Fix missing quotes --- hooks/iosAddTarget.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hooks/iosAddTarget.js b/hooks/iosAddTarget.js index f721547..3b88ed1 100755 --- a/hooks/iosAddTarget.js +++ b/hooks/iosAddTarget.js @@ -321,7 +321,7 @@ module.exports = function (context) { buildSettingsObj['PROVISIONING_PROFILE'] = PROVISIONING_PROFILE; buildSettingsObj['DEVELOPMENT_TEAM'] = DEVELOPMENT_TEAM; buildSettingsObj['CODE_SIGN_STYLE'] = 'Manual'; - buildSettingsObj['CODE_SIGN_IDENTITY'] = 'iPhone Distribution'; + buildSettingsObj['CODE_SIGN_IDENTITY'] = '"iPhone Distribution"'; console.log('Added signing identities for extension!'); } }