From 34bf878d97019cb4924f99e63a32e4c136449609 Mon Sep 17 00:00:00 2001 From: X-Net Mac Date: Thu, 13 Jul 2017 19:13:43 +0200 Subject: [PATCH 1/2] option to force usage of contentType on ios --- src/ios/FileOpener2.m | 20 +++++++++++++++----- www/plugins.FileOpener2.js | 6 ++++++ 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/ios/FileOpener2.m b/src/ios/FileOpener2.m index 6f238e4..4cc8cd0 100644 --- a/src/ios/FileOpener2.m +++ b/src/ios/FileOpener2.m @@ -34,22 +34,32 @@ 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; + BOOL useContentType = NO; - if([command.arguments count] == 2) { // Includes contentType + if([command.arguments count] >= 2) { // Includes contentType contentType = [command.arguments objectAtIndex:1]; } - if ([command.arguments count] == 3) { + if ([command.arguments count] >= 3) { showPreview = [[command.arguments objectAtIndex:2] boolValue]; } + if ([command.arguments count] >= 4) { + useContentType = [[command.arguments objectAtIndex:3] boolValue]; + } + CDVViewController* cont = (CDVViewController*)[super viewController]; self.cdvViewController = cont; + NSString *uti = nil; - NSArray *dotParts = [path componentsSeparatedByString:@"."]; - NSString *fileExt = [dotParts lastObject]; + if(useContentType){ + uti = (__bridge NSString *)UTTypeCreatePreferredIdentifierForTag(kUTTagClassMIMEType, (__bridge CFStringRef)contentType, NULL); + } else { + NSArray *dotParts = [path componentsSeparatedByString:@"."]; + NSString *fileExt = [dotParts lastObject]; - NSString *uti = (__bridge NSString *)UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (__bridge CFStringRef)fileExt, NULL); + uti = (__bridge NSString *)UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (__bridge CFStringRef)fileExt, NULL); + } dispatch_async(dispatch_get_main_queue(), ^{ NSURL *fileURL = [NSURL URLWithString:path]; diff --git a/www/plugins.FileOpener2.js b/www/plugins.FileOpener2.js index c5face4..eb75211 100644 --- a/www/plugins.FileOpener2.js +++ b/www/plugins.FileOpener2.js @@ -36,6 +36,12 @@ FileOpener2.prototype.showOpenWithDialog = function (fileName, contentType, call exec(callbackContext.success || null, callbackContext.error || null, 'FileOpener2', 'open', [fileName, contentType, false]); }; +FileOpener2.prototype.openWithContentType = function (fileName, contentType, callbackContext) { + callbackContext = callbackContext || {}; + if(typeof contentType !== "string"){ throw new Error("contentType must be a String") } + exec(callbackContext.success || null, callbackContext.error || null, 'FileOpener2', 'open', [fileName, contentType, true, true]); +}; + FileOpener2.prototype.uninstall = function (packageId, callbackContext) { callbackContext = callbackContext || {}; exec(callbackContext.success || null, callbackContext.error || null, 'FileOpener2', 'uninstall', [packageId]); From 538cd1305fc3341eb7761b174eeba451cd3ca350 Mon Sep 17 00:00:00 2001 From: X-Net Mac Date: Tue, 25 Jul 2017 08:53:34 +0200 Subject: [PATCH 2/2] iOS: use mimetype if provided, otherwise fall back to file extension --- src/ios/FileOpener2.m | 19 +++++-------------- www/plugins.FileOpener2.js | 6 ------ 2 files changed, 5 insertions(+), 20 deletions(-) diff --git a/src/ios/FileOpener2.m b/src/ios/FileOpener2.m index 4cc8cd0..257a356 100644 --- a/src/ios/FileOpener2.m +++ b/src/ios/FileOpener2.m @@ -31,34 +31,25 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - (void) open: (CDVInvokedUrlCommand*)command { - NSString *path = [[command.arguments objectAtIndex:0] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; - NSString *contentType = nil; + NSString *path = [[command.arguments objectAtIndex:0] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; + NSString *contentType = [command.arguments objectAtIndex:1]; BOOL showPreview = YES; - BOOL useContentType = NO; - - if([command.arguments count] >= 2) { // Includes contentType - contentType = [command.arguments objectAtIndex:1]; - } if ([command.arguments count] >= 3) { showPreview = [[command.arguments objectAtIndex:2] boolValue]; } - if ([command.arguments count] >= 4) { - useContentType = [[command.arguments objectAtIndex:3] boolValue]; - } - CDVViewController* cont = (CDVViewController*)[super viewController]; self.cdvViewController = cont; NSString *uti = nil; - if(useContentType){ - uti = (__bridge NSString *)UTTypeCreatePreferredIdentifierForTag(kUTTagClassMIMEType, (__bridge CFStringRef)contentType, NULL); - } else { + if([contentType length] == 0){ NSArray *dotParts = [path componentsSeparatedByString:@"."]; NSString *fileExt = [dotParts lastObject]; uti = (__bridge NSString *)UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (__bridge CFStringRef)fileExt, NULL); + } else { + uti = (__bridge NSString *)UTTypeCreatePreferredIdentifierForTag(kUTTagClassMIMEType, (__bridge CFStringRef)contentType, NULL); } dispatch_async(dispatch_get_main_queue(), ^{ diff --git a/www/plugins.FileOpener2.js b/www/plugins.FileOpener2.js index bac1a50..ebe9313 100644 --- a/www/plugins.FileOpener2.js +++ b/www/plugins.FileOpener2.js @@ -38,12 +38,6 @@ FileOpener2.prototype.showOpenWithDialog = function (fileName, contentType, call exec(callbackContext.success || null, callbackContext.error || null, 'FileOpener2', 'open', [fileName, contentType, false]); }; -FileOpener2.prototype.openWithContentType = function (fileName, contentType, callbackContext) { - callbackContext = callbackContext || {}; - if(typeof contentType !== "string"){ throw new Error("contentType must be a String") } - exec(callbackContext.success || null, callbackContext.error || null, 'FileOpener2', 'open', [fileName, contentType, true, true]); -}; - FileOpener2.prototype.uninstall = function (packageId, callbackContext) { callbackContext = callbackContext || {}; exec(callbackContext.success || null, callbackContext.error || null, 'FileOpener2', 'uninstall', [packageId]);