From bbeb4a1227360f07942efe14966aa832bd326093 Mon Sep 17 00:00:00 2001 From: Sergii Stotskyi Date: Thu, 20 Apr 2017 18:36:43 +0300 Subject: [PATCH] feat(ios): adds method for opening openWith dialog on iOS --- src/ios/FileOpener2.m | 15 ++++++++++++++- www/plugins.FileOpener2.js | 7 ++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/ios/FileOpener2.m b/src/ios/FileOpener2.m index 318e63f..6f238e4 100644 --- a/src/ios/FileOpener2.m +++ b/src/ios/FileOpener2.m @@ -33,11 +33,16 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. NSString *path = [[command.arguments objectAtIndex:0] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; NSString *contentType = nil; + BOOL showPreview = YES; if([command.arguments count] == 2) { // Includes contentType contentType = [command.arguments objectAtIndex:1]; } + if ([command.arguments count] == 3) { + showPreview = [[command.arguments objectAtIndex:2] boolValue]; + } + CDVViewController* cont = (CDVViewController*)[super viewController]; self.cdvViewController = cont; @@ -68,7 +73,15 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. CDVPluginResult* pluginResult = nil; //Opens the file preview - BOOL wasOpened = [docController presentPreviewAnimated: NO]; + BOOL wasOpened = NO; + + if (showPreview) { + wasOpened = [docController presentPreviewAnimated: NO]; + } else { + CDVViewController* cont = self.cdvViewController; + CGRect rect = CGRectMake(0, 0, cont.view.bounds.size.width, cont.view.bounds.size.height); + wasOpened = [docController presentOpenInMenuFromRect:rect inView:cont.view animated:YES]; + } if(wasOpened) { pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: @""]; diff --git a/www/plugins.FileOpener2.js b/www/plugins.FileOpener2.js index 06519dd..c5face4 100644 --- a/www/plugins.FileOpener2.js +++ b/www/plugins.FileOpener2.js @@ -31,6 +31,11 @@ FileOpener2.prototype.open = function (fileName, contentType, callbackContext) { exec(callbackContext.success || null, callbackContext.error || null, 'FileOpener2', 'open', [fileName, contentType]); }; +FileOpener2.prototype.showOpenWithDialog = function (fileName, contentType, callbackContext) { + callbackContext = callbackContext || {}; + exec(callbackContext.success || null, callbackContext.error || null, 'FileOpener2', 'open', [fileName, contentType, false]); +}; + FileOpener2.prototype.uninstall = function (packageId, callbackContext) { callbackContext = callbackContext || {}; exec(callbackContext.success || null, callbackContext.error || null, 'FileOpener2', 'uninstall', [packageId]); @@ -41,4 +46,4 @@ FileOpener2.prototype.appIsInstalled = function (packageId, callbackContext) { exec(callbackContext.success || null, callbackContext.error || null, 'FileOpener2', 'appIsInstalled', [packageId]); }; -module.exports = new FileOpener2(); \ No newline at end of file +module.exports = new FileOpener2();