mirror of
https://gitee.com/shuto/cordova-plugin-file-opener2.git
synced 2025-01-31 12:02:49 +08:00
Merge pull request #306 from aleksilahis/bug/ios_cant_display_multiple_open_in_menus
Return result after dismissing interaction controller to allow multiple files to be opened consecutively on iOS
This commit is contained in:
commit
2613a8abef
@ -29,9 +29,12 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||||||
@implementation FileOpener2
|
@implementation FileOpener2
|
||||||
@synthesize controller = docController;
|
@synthesize controller = docController;
|
||||||
|
|
||||||
- (void) open: (CDVInvokedUrlCommand*)command {
|
CDVPluginResult* pluginResult = nil;
|
||||||
|
NSString* callbackId = nil;
|
||||||
|
|
||||||
NSString *path = [command.arguments objectAtIndex:0];
|
- (void) open: (CDVInvokedUrlCommand*)command {
|
||||||
|
callbackId = command.callbackId;
|
||||||
|
NSString *path = [command.arguments objectAtIndex:0];
|
||||||
NSString *contentType = [command.arguments objectAtIndex:1];
|
NSString *contentType = [command.arguments objectAtIndex:1];
|
||||||
BOOL showPreview = YES;
|
BOOL showPreview = YES;
|
||||||
|
|
||||||
@ -43,7 +46,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||||||
self.cdvViewController = cont;
|
self.cdvViewController = cont;
|
||||||
NSString *uti = nil;
|
NSString *uti = nil;
|
||||||
|
|
||||||
if([contentType length] == 0){
|
if ([contentType length] == 0) {
|
||||||
NSArray *dotParts = [path componentsSeparatedByString:@"."];
|
NSArray *dotParts = [path componentsSeparatedByString:@"."];
|
||||||
NSString *fileExt = [dotParts lastObject];
|
NSString *fileExt = [dotParts lastObject];
|
||||||
|
|
||||||
@ -55,42 +58,43 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
NSURL *fileURL = NULL;
|
NSURL *fileURL = NULL;
|
||||||
NSString *decodedPath = [path stringByRemovingPercentEncoding];
|
NSString *decodedPath = [path stringByRemovingPercentEncoding];
|
||||||
|
|
||||||
if ([path isEqualToString:decodedPath]) {
|
if ([path isEqualToString:decodedPath]) {
|
||||||
NSLog(@"Path parameter not encoded. Building file URL encoding it...");
|
NSLog(@"Path parameter not encoded. Building file URL encoding it...");
|
||||||
fileURL = [NSURL fileURLWithPath:[path stringByReplacingOccurrencesOfString:@"file://" withString:@""]];;
|
fileURL = [NSURL fileURLWithPath:[path stringByReplacingOccurrencesOfString:@"file://" withString:@""]];;
|
||||||
} else {
|
} else {
|
||||||
NSLog(@"Path parameter already encoded. Building file URL without encoding it...");
|
NSLog(@"Path parameter already encoded. Building file URL without encoding it...");
|
||||||
fileURL = [NSURL URLWithString:path];
|
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]) {
|
||||||
NSDictionary *jsonObj = @{@"status" : @"9",
|
NSDictionary *jsonObj = @{@"status" : @"9",
|
||||||
@"message" : @"File does not exist"};
|
@"message" : @"File does not exist"};
|
||||||
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:jsonObj];
|
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:jsonObj];
|
||||||
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
|
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
docController = [UIDocumentInteractionController interactionControllerWithURL:fileURL];
|
docController = [UIDocumentInteractionController interactionControllerWithURL:fileURL];
|
||||||
docController.delegate = self;
|
docController.delegate = self;
|
||||||
docController.UTI = uti;
|
docController.UTI = uti;
|
||||||
|
|
||||||
CDVPluginResult* pluginResult = nil;
|
|
||||||
|
|
||||||
//Opens the file preview
|
//Opens the file preview
|
||||||
CGRect rect;
|
CGRect rect;
|
||||||
|
|
||||||
if ([command.arguments count] >= 4) {
|
if ([command.arguments count] >= 4) {
|
||||||
NSArray *positionValues = [command.arguments objectAtIndex:3];
|
NSArray *positionValues = [command.arguments objectAtIndex:3];
|
||||||
|
|
||||||
if (![positionValues isEqual:[NSNull null]] && [positionValues count] >= 2) {
|
if (![positionValues isEqual:[NSNull null]] && [positionValues count] >= 2) {
|
||||||
rect = CGRectMake(0, 0, [[positionValues objectAtIndex:0] floatValue], [[positionValues objectAtIndex:1] floatValue]);
|
rect = CGRectMake(0, 0, [[positionValues objectAtIndex:0] floatValue], [[positionValues objectAtIndex:1] floatValue]);
|
||||||
} else {
|
} else {
|
||||||
rect = CGRectMake(0, 0, 0, 0);
|
rect = CGRectMake(0, 0, 0, 0);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
rect = CGRectMake(0, 0, cont.view.bounds.size.width, cont.view.bounds.size.height);
|
rect = CGRectMake(0, 0, cont.view.bounds.size.width, cont.view.bounds.size.height);
|
||||||
}
|
}
|
||||||
@ -104,9 +108,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||||||
wasOpened = [docController presentOpenInMenuFromRect:rect inView:cont.view animated:YES];
|
wasOpened = [docController presentOpenInMenuFromRect:rect inView:cont.view animated:YES];
|
||||||
}
|
}
|
||||||
|
|
||||||
if(wasOpened) {
|
if (wasOpened) {
|
||||||
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: @""];
|
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: @""];
|
||||||
//NSLog(@"Success");
|
|
||||||
} else {
|
} else {
|
||||||
NSDictionary *jsonObj = [ [NSDictionary alloc]
|
NSDictionary *jsonObj = [ [NSDictionary alloc]
|
||||||
initWithObjectsAndKeys :
|
initWithObjectsAndKeys :
|
||||||
@ -115,23 +118,34 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||||||
nil
|
nil
|
||||||
];
|
];
|
||||||
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:jsonObj];
|
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:jsonObj];
|
||||||
|
[self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
|
||||||
}
|
}
|
||||||
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation FileOpener2 (UIDocumentInteractionControllerDelegate)
|
@implementation FileOpener2 (UIDocumentInteractionControllerDelegate)
|
||||||
- (UIViewController *)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller {
|
- (void)documentInteractionControllerDidDismissOpenInMenu:(UIDocumentInteractionController *)controller {
|
||||||
UIViewController *presentingViewController = self.viewController;
|
[self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
|
||||||
if (presentingViewController.view.window != [UIApplication sharedApplication].keyWindow){
|
}
|
||||||
presentingViewController = [UIApplication sharedApplication].keyWindow.rootViewController;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (presentingViewController.presentedViewController != nil && ![presentingViewController.presentedViewController isBeingDismissed]){
|
- (void)documentInteractionControllerDidEndPreview:(UIDocumentInteractionController *)controller {
|
||||||
presentingViewController = presentingViewController.presentedViewController;
|
[self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
|
||||||
}
|
}
|
||||||
return presentingViewController;
|
|
||||||
|
- (UIViewController *)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller {
|
||||||
|
UIViewController *presentingViewController = self.viewController;
|
||||||
|
|
||||||
|
if (presentingViewController.view.window != [UIApplication sharedApplication].keyWindow) {
|
||||||
|
presentingViewController = [UIApplication sharedApplication].keyWindow.rootViewController;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
while (presentingViewController.presentedViewController != nil && ![presentingViewController.presentedViewController isBeingDismissed]) {
|
||||||
|
presentingViewController = presentingViewController.presentedViewController;
|
||||||
|
}
|
||||||
|
|
||||||
|
return presentingViewController;
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
Loading…
Reference in New Issue
Block a user