feat(ios): adds method for opening openWith dialog on iOS

This commit is contained in:
Sergii Stotskyi 2017-04-20 18:36:43 +03:00
parent bc40c0a879
commit bbeb4a1227
2 changed files with 20 additions and 2 deletions

View File

@ -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: @""];

View File

@ -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();
module.exports = new FileOpener2();