Is there an elegant way to access the camera from the inappbrowser under iOS?

旧城冷巷雨未停 提交于 2019-12-08 04:32:01

问题


I am currently developing an hybrid app with Cordova. The project is mainly a webview for an external website (implemented with the Cordova inappbrowser plugin). On this site I want the user to be able to take a picture with their device camera and use it on the website. On Android I intercept the "loadstart" event and launch the camera plugin for a specific url, which works just as I want it to. On iOS however, the camera does not launch and I get a warning
Warning: Attempt to present <CDVCameraPicker: 0xXXXXXXXXX> on <MainViewController: 0xXXX> whose view is not in the window hierarchy!
in XCode.
After some research I found out, that this is expected behaviour for the inappbrowser. Closing the inappbrowser to launch the camera and open the inappbrowser again is no option for me.

Question 1: Is it possible to show the camera on top of the inappbrowser?

My workaroud so far is to use <input type="file" accept="image/*" capture="camera">, which works (kind of). It opens a dialog where the user can choose between "take picture" and "choose file", if he chooses "take picture" the camera opens and I can get the picture to the website.

Question 2: Can I bypass this choose dialog and go directly to the camera when the button is clicked?

I know that both modifications have to take place in native iOS code (which I have never used).
Any help will be appreciated and THANK YOU for your time.

Related question:

  • Cordova IOS camera plugin not working when trying to open from inappbrowser


Update:

The call which seems to break the camera is:

__weak CDVCamera* weakSelf = self;

...

[weakSelf.viewController presentViewController:cameraPicker animated:YES completion:^{
    weakSelf.hasPendingOperation = NO;
}];

Question: How can I present the camera on top of the inappbrowser plugin?

I tried to get the rootViewController but it did not work:

  • [[[[UIApplication sharedApplication] delegate] window] rootViewController]

来源:https://stackoverflow.com/questions/38920198/is-there-an-elegant-way-to-access-the-camera-from-the-inappbrowser-under-ios

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