option to force usage of contentType on ios

This commit is contained in:
X-Net Mac 2017-07-13 19:13:43 +02:00
parent f08a0fb154
commit 34bf878d97
2 changed files with 21 additions and 5 deletions

View File

@ -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 *path = [[command.arguments objectAtIndex:0] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *contentType = nil; NSString *contentType = nil;
BOOL showPreview = YES; 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]; contentType = [command.arguments objectAtIndex:1];
} }
if ([command.arguments count] == 3) { if ([command.arguments count] >= 3) {
showPreview = [[command.arguments objectAtIndex:2] boolValue]; showPreview = [[command.arguments objectAtIndex:2] boolValue];
} }
if ([command.arguments count] >= 4) {
useContentType = [[command.arguments objectAtIndex:3] boolValue];
}
CDVViewController* cont = (CDVViewController*)[super viewController]; CDVViewController* cont = (CDVViewController*)[super viewController];
self.cdvViewController = cont; self.cdvViewController = cont;
NSString *uti = nil;
NSArray *dotParts = [path componentsSeparatedByString:@"."]; if(useContentType){
NSString *fileExt = [dotParts lastObject]; 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(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
NSURL *fileURL = [NSURL URLWithString:path]; NSURL *fileURL = [NSURL URLWithString:path];

View File

@ -36,6 +36,12 @@ FileOpener2.prototype.showOpenWithDialog = function (fileName, contentType, call
exec(callbackContext.success || null, callbackContext.error || null, 'FileOpener2', 'open', [fileName, contentType, false]); 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) { FileOpener2.prototype.uninstall = function (packageId, callbackContext) {
callbackContext = callbackContext || {}; callbackContext = callbackContext || {};
exec(callbackContext.success || null, callbackContext.error || null, 'FileOpener2', 'uninstall', [packageId]); exec(callbackContext.success || null, callbackContext.error || null, 'FileOpener2', 'uninstall', [packageId]);