From 6d712ad889e7a676443467cc05ed1fc5f06814a7 Mon Sep 17 00:00:00 2001 From: Seamus Campbell Date: Sat, 7 Mar 2015 14:18:59 -0800 Subject: [PATCH] Basic functional file URI opening. * does not take paths or cdvfile:// URIs. * still exposes iOS 8 bug with UIDocumentInteractionController see http://openradar.appspot.com/radar?id=5800473659441152 --- src/ios/FileOpener2.m | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/src/ios/FileOpener2.m b/src/ios/FileOpener2.m index b76083c..8e9d611 100644 --- a/src/ios/FileOpener2.m +++ b/src/ios/FileOpener2.m @@ -30,32 +30,31 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - (void) open: (CDVInvokedUrlCommand*)command { - NSString *path = [command.arguments objectAtIndex:0]; - NSString *uti = nil; - if (command.arguments.count > 1) { - uti = [command.arguments objectAtIndex:1]; + NSString *path = command.arguments[0]; + NSString *uti = command.arguments[1]; + if (!uti || (NSNull*)uti == [NSNull null]) { + NSArray *dotParts = [path componentsSeparatedByString:@"."]; + NSString *fileExt = [dotParts lastObject]; + + uti = (__bridge NSString *)UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (__bridge CFStringRef)fileExt, NULL); } CDVViewController* cont = (CDVViewController*)[ super viewController ]; - if (!uti) { - NSArray *dotParts = [path componentsSeparatedByString:@"."]; - NSString *fileExt = [dotParts lastObject]; - - uti = (__bridge NSString *)UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (__bridge CFStringRef)fileExt, NULL); - } - dispatch_async(dispatch_get_main_queue(), ^{ - NSURL *fileURL = [NSURL fileURLWithPath:path]; + // TODO: test if this is a URI or a path + NSURL *fileURL = [NSURL URLWithString:path]; localFile = fileURL.path; NSLog(@"looking for file at %@", fileURL); NSFileManager *fm = [NSFileManager defaultManager]; if(![fm fileExistsAtPath:localFile]) { - NSLog(@"couldn't find file!"); - } else { - NSLog(@"file located, handing off to UIDocumentInteractionController"); + NSDictionary *jsonObj = @{@"status" : @"9", + @"message" : @"File does not exist"}; + pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR + messageAsDictionary:jsonObj]; + return; } self.controller = [UIDocumentInteractionController interactionControllerWithURL:fileURL];