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
This commit is contained in:
Seamus Campbell 2015-03-07 14:18:59 -08:00
parent 56b0c4ddd6
commit 6d712ad889

View File

@ -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];
}
CDVViewController* cont = (CDVViewController*)[ super viewController ];
if (!uti) {
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 ];
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];