mirror of
https://gitee.com/shuto/cordova-plugin-file-opener2.git
synced 2025-01-31 12:02:49 +08:00
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:
parent
56b0c4ddd6
commit
6d712ad889
@ -30,32 +30,31 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||||||
|
|
||||||
- (void) open: (CDVInvokedUrlCommand*)command {
|
- (void) open: (CDVInvokedUrlCommand*)command {
|
||||||
|
|
||||||
NSString *path = [command.arguments objectAtIndex:0];
|
NSString *path = command.arguments[0];
|
||||||
NSString *uti = nil;
|
NSString *uti = command.arguments[1];
|
||||||
if (command.arguments.count > 1) {
|
if (!uti || (NSNull*)uti == [NSNull null]) {
|
||||||
uti = [command.arguments objectAtIndex:1];
|
|
||||||
}
|
|
||||||
|
|
||||||
CDVViewController* cont = (CDVViewController*)[ super viewController ];
|
|
||||||
|
|
||||||
if (!uti) {
|
|
||||||
NSArray *dotParts = [path componentsSeparatedByString:@"."];
|
NSArray *dotParts = [path componentsSeparatedByString:@"."];
|
||||||
NSString *fileExt = [dotParts lastObject];
|
NSString *fileExt = [dotParts lastObject];
|
||||||
|
|
||||||
uti = (__bridge NSString *)UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (__bridge CFStringRef)fileExt, NULL);
|
uti = (__bridge NSString *)UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (__bridge CFStringRef)fileExt, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CDVViewController* cont = (CDVViewController*)[ super viewController ];
|
||||||
|
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
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;
|
localFile = fileURL.path;
|
||||||
|
|
||||||
NSLog(@"looking for file at %@", fileURL);
|
NSLog(@"looking for file at %@", fileURL);
|
||||||
NSFileManager *fm = [NSFileManager defaultManager];
|
NSFileManager *fm = [NSFileManager defaultManager];
|
||||||
if(![fm fileExistsAtPath:localFile]) {
|
if(![fm fileExistsAtPath:localFile]) {
|
||||||
NSLog(@"couldn't find file!");
|
NSDictionary *jsonObj = @{@"status" : @"9",
|
||||||
} else {
|
@"message" : @"File does not exist"};
|
||||||
NSLog(@"file located, handing off to UIDocumentInteractionController");
|
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR
|
||||||
|
messageAsDictionary:jsonObj];
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.controller = [UIDocumentInteractionController interactionControllerWithURL:fileURL];
|
self.controller = [UIDocumentInteractionController interactionControllerWithURL:fileURL];
|
||||||
|
Loading…
Reference in New Issue
Block a user