pwlin / cordova-plugin-file-opener2

A File Opener Plugin for Cordova
MIT License
314 stars 584 forks source link

(iOS) UIDocumentInteractionController not appearing on top of the existing view controller #275

Closed lovelyelfpop closed 4 years ago

lovelyelfpop commented 4 years ago

I use webkit.messageHandlers.cordova_iab.postMessage inside InAppBrowser to notify cordova webview to show file opener menu, but the menu shows behind the inappbrowser.

shnist commented 4 years ago

hi @lovelyelfpop, I'm a little confused, in what way are you using this plugin?

lovelyelfpop commented 4 years ago

InAppbrowser can not call cordova plugins' methods, so I use postMessage to cordova webview and let cordova webview to handle it

shnist commented 4 years ago

Can you share with me the code you have written so I can see what are you doing more clearly please?

lovelyelfpop commented 4 years ago

Inside inappbrowser:

webkit.messageHandlers.cordova_iab.postMessage(JSON.stringify({
    action: "openFile",
    path: "file:///var/mobile/Applications/xxx-xxx-xxx-xxxx/Documents/1.docx"
}));

In cordova:

var ref = window.open('http://remote.site.page', '_blank', '');
ref.addEventListener('message', function (params) {
    var data = params.data;
    if (data.action== 'openFile') {
        cordova.plugins.fileOpener2.open(
            data.path,
            null,
            {
                error : function(){ },
                success : function(){ }
            }
        );
    }
});
lovelyelfpop commented 4 years ago

Use code below to find top most viewController and presentOptionsMenuFromRect in it

- (UIViewController *)getPresentedViewController
{
    UIViewController *appRootVC = [UIApplication sharedApplication].keyWindow.rootViewController;
    UIViewController *topVC = appRootVC;
    if (topVC.presentedViewController) {
        topVC = topVC.presentedViewController;
    }
    return topVC;
}
pwlin commented 4 years ago

You shouldn't need to hack anything in Objective-C to achieve this. Use InAppBrowser.hide function to hide the child window.