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,8 +29,11 @@ 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;
|
||||||
|
|
||||||
|
- (void) open: (CDVInvokedUrlCommand*)command {
|
||||||
|
callbackId = command.callbackId;
|
||||||
NSString *path = [command.arguments objectAtIndex:0];
|
NSString *path = [command.arguments objectAtIndex:0];
|
||||||
NSString *contentType = [command.arguments objectAtIndex:1];
|
NSString *contentType = [command.arguments objectAtIndex:1];
|
||||||
BOOL showPreview = YES;
|
BOOL showPreview = YES;
|
||||||
@ -55,6 +58,7 @@ 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:@""]];;
|
||||||
@ -67,6 +71,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||||||
|
|
||||||
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"};
|
||||||
@ -79,10 +84,9 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||||||
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];
|
||||||
|
|
||||||
@ -106,7 +110,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||||||
|
|
||||||
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,16 +118,25 @@ 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)
|
||||||
|
- (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 *)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller {
|
||||||
UIViewController *presentingViewController = self.viewController;
|
UIViewController *presentingViewController = self.viewController;
|
||||||
|
|
||||||
if (presentingViewController.view.window != [UIApplication sharedApplication].keyWindow) {
|
if (presentingViewController.view.window != [UIApplication sharedApplication].keyWindow) {
|
||||||
presentingViewController = [UIApplication sharedApplication].keyWindow.rootViewController;
|
presentingViewController = [UIApplication sharedApplication].keyWindow.rootViewController;
|
||||||
}
|
}
|
||||||
@ -132,6 +144,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||||||
while (presentingViewController.presentedViewController != nil && ![presentingViewController.presentedViewController isBeingDismissed]) {
|
while (presentingViewController.presentedViewController != nil && ![presentingViewController.presentedViewController isBeingDismissed]) {
|
||||||
presentingViewController = presentingViewController.presentedViewController;
|
presentingViewController = presentingViewController.presentedViewController;
|
||||||
}
|
}
|
||||||
|
|
||||||
return presentingViewController;
|
return presentingViewController;
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
Loading…
Reference in New Issue
Block a user