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:
pwlin 2020-09-14 12:49:29 +01:00 committed by GitHub
commit 2613a8abef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -29,8 +29,11 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@implementation FileOpener2
@synthesize controller = docController;
- (void) open: (CDVInvokedUrlCommand*)command {
CDVPluginResult* pluginResult = nil;
NSString* callbackId = nil;
- (void) open: (CDVInvokedUrlCommand*)command {
callbackId = command.callbackId;
NSString *path = [command.arguments objectAtIndex:0];
NSString *contentType = [command.arguments objectAtIndex:1];
BOOL showPreview = YES;
@ -43,7 +46,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
self.cdvViewController = cont;
NSString *uti = nil;
if([contentType length] == 0){
if ([contentType length] == 0) {
NSArray *dotParts = [path componentsSeparatedByString:@"."];
NSString *fileExt = [dotParts lastObject];
@ -55,6 +58,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
dispatch_async(dispatch_get_main_queue(), ^{
NSURL *fileURL = NULL;
NSString *decodedPath = [path stringByRemovingPercentEncoding];
if ([path isEqualToString:decodedPath]) {
NSLog(@"Path parameter not encoded. Building file URL encoding it...");
fileURL = [NSURL fileURLWithPath:[path stringByReplacingOccurrencesOfString:@"file://" withString:@""]];;
@ -67,7 +71,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
NSLog(@"looking for file at %@", fileURL);
NSFileManager *fm = [NSFileManager defaultManager];
if(![fm fileExistsAtPath:localFile]) {
if (![fm fileExistsAtPath:localFile]) {
NSDictionary *jsonObj = @{@"status" : @"9",
@"message" : @"File does not exist"};
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:jsonObj];
@ -79,10 +84,9 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
docController.delegate = self;
docController.UTI = uti;
CDVPluginResult* pluginResult = nil;
//Opens the file preview
CGRect rect;
if ([command.arguments count] >= 4) {
NSArray *positionValues = [command.arguments objectAtIndex:3];
@ -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];
}
if(wasOpened) {
if (wasOpened) {
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: @""];
//NSLog(@"Success");
} else {
NSDictionary *jsonObj = [ [NSDictionary alloc]
initWithObjectsAndKeys :
@ -115,23 +118,34 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
nil
];
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:jsonObj];
[self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
}
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
});
}
@end
@implementation FileOpener2 (UIDocumentInteractionControllerDelegate)
- (UIViewController *)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller {
- (void)documentInteractionControllerDidDismissOpenInMenu:(UIDocumentInteractionController *)controller {
[self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
}
- (void)documentInteractionControllerDidEndPreview:(UIDocumentInteractionController *)controller {
[self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
}
- (UIViewController *)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller {
UIViewController *presentingViewController = self.viewController;
if (presentingViewController.view.window != [UIApplication sharedApplication].keyWindow){
if (presentingViewController.view.window != [UIApplication sharedApplication].keyWindow) {
presentingViewController = [UIApplication sharedApplication].keyWindow.rootViewController;
}
while (presentingViewController.presentedViewController != nil && ![presentingViewController.presentedViewController isBeingDismissed]){
while (presentingViewController.presentedViewController != nil && ![presentingViewController.presentedViewController isBeingDismissed]) {
presentingViewController = presentingViewController.presentedViewController;
}
return presentingViewController;
}
}
@end