Skip to content

Commit

Permalink
Merge branch 'master' into remove-dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
NiklasMerz authored Mar 9, 2019
2 parents ac5e219 + ce53001 commit 847c99d
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 26 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.<YOUR_APP_BUNDLE_ID>.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).

Expand Down
28 changes: 28 additions & 0 deletions hooks/iosAddTarget.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
20 changes: 0 additions & 20 deletions hooks/iosRemoveTarget.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:[]};
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
24 changes: 24 additions & 0 deletions src/android/cc/fovea/openwith/Serializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/ios/ShareExtension/ShareViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -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__"
11 changes: 7 additions & 4 deletions src/ios/ShareExtension/ShareViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ - (void) submit {

[itemProvider loadItemForTypeIdentifier:SHAREEXT_UNIFORM_TYPE_IDENTIFIER options:nil completionHandler: ^(id<NSSecureCoding> item, NSError *error) {

NSData *data;
NSData *data = [[NSData alloc] init];
if([(NSObject*)item isKindOfClass:[NSURL class]]) {
data = [NSData dataWithContentsOfURL:(NSURL*)item];
}
Expand All @@ -137,18 +137,21 @@ - (void) submit {
suggestedName = [itemProvider valueForKey:@"suggestedName"];
}

NSString *uti = nil;
NSString *uti = @"";
NSArray<NSString *> *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"];
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 847c99d

Please sign in to comment.