当尝试从inappbrowser打开Cordova IOS相机插件不工作 [英] Cordova IOS camera plugin not working when trying to open from inappbrowser
问题描述
我正在使用cordova 6.0.0的混合移动应用程序。
根据我的要求,我必须在网络视图中打开动态网址。 url将由api响应提供。
我在应用程式浏览器外挂程式中使用cordova应用程式浏览器。
https://github.com/apache/cordova-plugin-inappbrowser
现在,当用户点击在Web视图中打开的页面中的任何链接时,我必须捕获该点击事件,并找到用户点击的锚标记的href值。
如果目标网址匹配我的条件,我必须打开相机,而不关闭网页视图,这样,即使在拍摄照片后,我可以保持网络视图的状态成功。
对于相机功能,我使用cordova默认的相机插件。
/ p>
但是在IOS的情况下,我不能打开相机。因为我已经检查控件是在相机插件内,但它是在下面警告
警告:尝试呈现< CDVCameraPicker:0x1570d1800> On< MainViewController:0x1565624a0>其视图不在窗口层次结构中!
我已经检查过很多与此相关的帖子,有些人建议使用Iframe而不是网络视图。但是我无法捕获动态加载的iframe中的点击事件。
有人可以帮助我应该是什么解决方案,是有任何方式,我可以做到
提前感谢
有同样的问题,设法解决它。您必须打开InaAppBrowser作为一个子视图显示摄像机在它的顶部。所有修改发生在CDVInAppBrowser.m中,如果InAppBrowser插件。
您必须修改CDVInAppBrowser的show方法:
dispatch_async(dispatch_get_main_queue(),^ {
if(weakSelf.inAppBrowserViewController!= nil){
//[weakSelf.viewController presentViewController:nav animated: YES completion:nil];
self.inAppBrowserViewController.view.frame = CGRectMake(0,20,self.inAppBrowserViewController.view.frame.size.width,self.inAppBrowserViewController.view.frame.size.height-20) ;
[self.viewController.view addSubview:self.inAppBrowserViewController.view];
}
});
只需删除已注释的行并添加注释行后的2。在CDVInAppBrowser的close方法中,您必须添加:
UIView * lastView;
for(UIView * subview in [self.viewController.view subviews]){
lastView = subview;
}
[lastView removeFromSuperview];
正在 [self.inAppBrowserViewController close];
。
完成后,相机现在会在inappbrowser的顶部打开,并将图像传递给它。
ps:记住删除并添加ios平台以应用更改
I am working for a hybrid mobile app using cordova 6.0.0.
According to my requirements , I have to open dynamic url in web view. The url would be provided by api response.
I am using the cordova in app browser plugin for web view.
https://github.com/apache/cordova-plugin-inappbrowser
Now when user clicks on any link in the page opened in the web view , I have to catch that click event and find the href value of the anchor tag on which user had clicked.
And if target url will match my condition , i have to open camera without closing the web view , so that i can maintain the state of web view even after picture was taken successfully.
For camera functionality i am using cordova default camera plugin.
I have done this successfully in Android.
But in case of IOS i am not able to open camera. As i have checked the control is going inside the camera plugin , but it is giving below warning
Warning: Attempt to present <CDVCameraPicker: 0x1570d1800> on <MainViewController: 0x1565624a0> whose view is not in the window hierarchy!
I have checked many posts regarding this and some peoples have suggested to use Iframe instead of web view. But i am not able to catch the click event in dynamically loaded Iframe.
Can someone please help what should be the solution for this , is there any way i can do this as per my requirements.
Thanks in advance
I recently had the same problem and managed to solve it. You have to open the InaAppBrowser as a subview to show the camera on top of it. All modifications take place in the CDVInAppBrowser.m if the InAppBrowser plugin.
You have to modify the show method of CDVInAppBrowser:
dispatch_async(dispatch_get_main_queue(), ^{
if (weakSelf.inAppBrowserViewController != nil) {
//[weakSelf.viewController presentViewController:nav animated:YES completion:nil];
self.inAppBrowserViewController.view.frame = CGRectMake(0,20,self.inAppBrowserViewController.view.frame.size.width,self.inAppBrowserViewController.view.frame.size.height-20);
[self.viewController.view addSubview:self.inAppBrowserViewController.view];
}
});
Just remove the commented line and add the 2 following the commented line. In the close method of CDVInAppBrowser you have to add:
UIView *lastView;
for(UIView *subview in [self.viewController.view subviews]) {
lastView = subview;
}
[lastView removeFromSuperview];
right before [self.inAppBrowserViewController close];
.
Done, the camera now opens on top of the inappbrowser and passes the image to it.
p.s.: remember to remove and add the ios platform in order to apply the changes
这篇关于当尝试从inappbrowser打开Cordova IOS相机插件不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!