diff --git a/README.md b/README.md index e53d32d..acb3e5e 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,9 @@ cordova plugin add cc.fovea.cordova.openwith \ | `ANDROID_MIME_TYPE` | image/* | **Android only** Mime type of documents you want to share (wildcards accepted) | | `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 | It shouldn't be too hard. But just in case, I [posted a screencast of it](https://youtu.be/eaE4m_xO1mg). diff --git a/hooks/iosAddTarget.js b/hooks/iosAddTarget.js index 36f2c71..eecb9da 100755 --- a/hooks/iosAddTarget.js +++ b/hooks/iosAddTarget.js @@ -151,12 +151,19 @@ 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') !== "") { + group = getCordovaParameter(configXml, 'IOS_GROUP_IDENTIFIER'); + } return [{ key: '__DISPLAY_NAME__', value: projectName }, { key: '__BUNDLE_IDENTIFIER__', value: plist.CFBundleIdentifier + BUNDLE_SUFFIX + } ,{ + key: '__GROUP_IDENTIFIER__', + value: group }, { key: '__BUNDLE_SHORT_VERSION_STRING__', value: plist.CFBundleShortVersionString @@ -280,6 +287,27 @@ module.exports = function (context) { pbxProject.addResourceFile(file.name, {target: target.uuid}, pbxGroupKey); }); + //Add development team and provisioning profile + var PROVISIONING_PROFILE = getCordovaParameter(configXml, 'SHAREEXT_PROVISIONING_PROFILE'); + var DEVELOPMENT_TEAM = getCordovaParameter(configXml, 'SHAREEXT_DEVELOPMENT_TEAM'); + console.log('Adding team', DEVELOPMENT_TEAM, 'and provisoning profile', PROVISIONING_PROFILE); + if (PROVISIONING_PROFILE && 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; + console.log('Added signing identities for extension!'); + } + } + } + } + } + // Add a new PBXFrameworksBuildPhase for the Frameworks used by the Share Extension // (NotificationCenter.framework, libCordova.a) // var frameworksBuildPhase = pbxProject.addBuildPhase( diff --git a/hooks/iosRemoveTarget.js b/hooks/iosRemoveTarget.js index e5c1df7..57fd411 100644 --- a/hooks/iosRemoveTarget.js +++ b/hooks/iosRemoveTarget.js @@ -110,26 +110,6 @@ function projectPlistJson(context, projectName) { return plist.parse(fs.readFileSync(path, 'utf8')); } -function getPreferences(context, projectName) { - var plist = projectPlistJson(context, projectName); - return [{ - key: '__DISPLAY_NAME__', - value: projectName - }, { - key: '__BUNDLE_IDENTIFIER__', - value: plist.CFBundleIdentifier + BUNDLE_SUFFIX - }, { - key: '__BUNDLE_SHORT_VERSION_STRING__', - value: plist.CFBundleShortVersionString - }, { - key: '__BUNDLE_VERSION__', - value: plist.CFBundleVersion - }, { - key: '__URL_KEY__', - value: plist.CFBundleIdentifier.replace(/[^a-zA-Z]/g, '').toLowerCase() - }]; -} - // Return the list of files in the share extension project, organized by type function getShareExtensionFiles(context) { var files = {source:[],plist:[],resource:[]}; diff --git a/package.json b/package.json index 4b23c1e..b40476d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cc.fovea.cordova.openwith", - "version": "1.1.0", + "version": "1.2.0", "description": "Cordova \"Open With\" plugin for iOS and Android", "cordova": { "id": "cc.fovea.cordova.openwith", diff --git a/src/android/cc/fovea/openwith/Serializer.java b/src/android/cc/fovea/openwith/Serializer.java index cedfd50..0bc6369 100644 --- a/src/android/cc/fovea/openwith/Serializer.java +++ b/src/android/cc/fovea/openwith/Serializer.java @@ -37,6 +37,9 @@ public static JSONObject toJSONObject( if (items == null || items.length() == 0) { items = itemsFromExtras(contentResolver, intent.getExtras()); } + if (items == null || items.length() == 0) { + items = itemsFromData(contentResolver, intent.getData()); + } if (items == null) { return null; } @@ -106,6 +109,27 @@ public static JSONArray itemsFromExtras( return new JSONArray(items); } + /** Extract the list of items from the intent's getData + * + * See Intent.ACTION_VIEW for details. */ + public static JSONArray itemsFromData( + final ContentResolver contentResolver, + final Uri uri) + throws JSONException { + if (uri == null) { + return null; + } + final JSONObject item = toJSONObject( + contentResolver, + uri); + if (item == null) { + return null; + } + final JSONObject[] items = new JSONObject[1]; + items[0] = item; + return new JSONArray(items); + } + /** Convert an Uri to JSON object. * * Object will include: diff --git a/src/ios/ShareExtension/ShareViewController.h b/src/ios/ShareExtension/ShareViewController.h index 9ba235d..f57416e 100644 --- a/src/ios/ShareExtension/ShareViewController.h +++ b/src/ios/ShareExtension/ShareViewController.h @@ -25,6 +25,6 @@ // THE SOFTWARE. // -#define SHAREEXT_GROUP_IDENTIFIER @"group.__BUNDLE_IDENTIFIER__" +#define SHAREEXT_GROUP_IDENTIFIER @"__GROUP_IDENTIFIER__" #define SHAREEXT_URL_SCHEME @"__URL_SCHEME__" #define SHAREEXT_UNIFORM_TYPE_IDENTIFIER @"__UNIFORM_TYPE_IDENTIFIER__" diff --git a/src/ios/ShareExtension/ShareViewController.m b/src/ios/ShareExtension/ShareViewController.m index 1b939b0..c41503a 100644 --- a/src/ios/ShareExtension/ShareViewController.m +++ b/src/ios/ShareExtension/ShareViewController.m @@ -124,7 +124,7 @@ - (void) submit { [itemProvider loadItemForTypeIdentifier:SHAREEXT_UNIFORM_TYPE_IDENTIFIER options:nil completionHandler: ^(id item, NSError *error) { - NSData *data; + NSData *data = [[NSData alloc] init]; if([(NSObject*)item isKindOfClass:[NSURL class]]) { data = [NSData dataWithContentsOfURL:(NSURL*)item]; } @@ -137,18 +137,21 @@ - (void) submit { suggestedName = [itemProvider valueForKey:@"suggestedName"]; } - NSString *uti = nil; + NSString *uti = @""; + NSArray *utis = [NSArray new]; if ([itemProvider.registeredTypeIdentifiers count] > 0) { uti = itemProvider.registeredTypeIdentifiers[0]; + utis = itemProvider.registeredTypeIdentifiers; } else { uti = SHAREEXT_UNIFORM_TYPE_IDENTIFIER; } NSDictionary *dict = @{ + @"text": self.contentText, @"backURL": self.backURL, @"data" : data, @"uti": uti, - @"utis": itemProvider.registeredTypeIdentifiers, + @"utis": utis, @"name": suggestedName }; [self.userDefaults setObject:dict forKey:@"image"]; @@ -231,7 +234,7 @@ - (NSString*) backURLFromBundleID: (NSString*)bundleId { // Wallet - com.apple.Passbook // Watch - com.apple.Bridge // Weather - com.apple.weather - return nil; + return @""; } // This is called at the point where the Post dialog is about to be shown.