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.
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.
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;
}