diff --git a/src/ios/FileOpener2.m b/src/ios/FileOpener2.m index 6f238e4..257a356 100644 --- a/src/ios/FileOpener2.m +++ b/src/ios/FileOpener2.m @@ -31,25 +31,26 @@ 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; - 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]; } CDVViewController* cont = (CDVViewController*)[super viewController]; self.cdvViewController = cont; + NSString *uti = nil; - NSArray *dotParts = [path componentsSeparatedByString:@"."]; - NSString *fileExt = [dotParts lastObject]; + if([contentType length] == 0){ + 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); + } else { + uti = (__bridge NSString *)UTTypeCreatePreferredIdentifierForTag(kUTTagClassMIMEType, (__bridge CFStringRef)contentType, NULL); + } dispatch_async(dispatch_get_main_queue(), ^{ NSURL *fileURL = [NSURL URLWithString:path];