Cordova iOS - InAppBrowser always on top issue

混江龙づ霸主 提交于 2019-12-22 00:55:49

问题


I am creating an Apache Cordova app. I have added InAppBrowser plugin and barcode scanner plugin that is invoked from the page opened inside InAppBrowser through cross browser communication. It is running perfectly fine in Android. But when ran in iOS, the InAppBrowser acts like a modal pop-up and doesn't let barcode scanner appear until the InAppBrowser is closed/dismissed.

I have confirmed that barcode scanner is working even when in background but it just won't appear because the InAppBrowser is always on top.

I'm thinking that there could be a workaround to give barcode scanner plugin maximum z-index but I cannot figure out how.

I also tried to hide the InAppBrowser, but it didn't work in iOS.

cordova.InAppBrowser.hide();

My idea is to extend my website to use native features when running from its mobile app.


回答1:


I did have the same issue. There is already an issue open at https://issues.apache.org/jira/browse/CB-12586 , which helped me to fix it.

The owner of the issue found a solution by changing the code of the hide() method of the InAppBrowser Plugin in your iOS folder (e.g. YourApp/platforms/ios/YourApp/Plugins/cordova-plugin-inappbrowser/CDVInAppBrowser.m). After applying the suggested solution my hide method looked like this:

- (void)hide:(CDVInvokedUrlCommand*)command
{
    if (self.inAppBrowserViewController == nil) {
        NSLog(@"Tried to hide IAB after it was closed.");
        return;


    }
    if (_previousStatusBarStyle == -1) {
        NSLog(@"Tried to hide IAB while already hidden");
        return;
    }

    _previousStatusBarStyle = [UIApplication sharedApplication].statusBarStyle;

    __weak CDVInAppBrowser* weakSelf = self;

    // Run later to avoid the "took a long time" log message.
    dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        if (weakSelf.inAppBrowserViewController != nil) {
            _previousStatusBarStyle = -1;
            [weakSelf.inAppBrowserViewController.presentingViewController dismissViewControllerAnimated:YES completion:nil];
        }
    });
}

After the next "cordova build", the hide methods worked for me. Let me know, if you found a better solution.




回答2:


I forgot to add an answer here. But I fixed it the very next day. The fix is very straight forward, I changed the hide and show methods of InAppBrowser to the following:

- (void)hide:(CDVInvokedUrlCommand*)command {
 self.inAppBrowserViewController.viewController.hidden = YES;
}

- (void)hide:(CDVInvokedUrlCommand*)command {
 self.inAppBrowserViewController.viewController.hidden = NO;

}



来源:https://stackoverflow.com/questions/43207732/cordova-ios-inappbrowser-always-on-top-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!