这是一个不同的问题,但仍然是关于我原来的问题:
Is there an elegant way to access the camera from the inappbrowser under iOS?
tl; dr:我想打开inappbrowser插件顶部的cordova相机插件(查看层次结构问题)
在我的第一个方法(旧问题)没有引导我到任何地方后,我试图修改inappbrowser (gitlink)。我希望它是cordova视图的子视图,以下代码设法完成:
__weak CDVInAppBrowser* weakSelf = self;
dispatch_async(dispatch_get_main_queue(), ^{
if (weakSelf.inAppBrowserViewController != nil) {
//[weakSelf.viewController presentViewController:nav animated:YES completion:nil];
[self.viewController.view addSubview:self.inAppBrowserViewController.view];
}
});
要关闭inappbrowser,我使用修改后的close方法:
- (void)close:(CDVInvokedUrlCommand*)command
{
if (self.inAppBrowserViewController != nil) {
UIView *lastView;
for(UIView *subview in [self.viewController.view subviews]) {
lastView = subview;
}
[lastView removeFromSuperview];
if (self.callbackId != nil) {
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK
messageAsDictionary:@{@"type":@"exit"}];
[self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackId];
}
self.inAppBrowserViewController.navigationDelegate = nil;
self.inAppBrowserViewController = nil;
_previousStatusBarStyle = -1;
}
}
请记住,我没有目标c的经验,也不知道我在做什么,我将不胜感激任何提示。
这两个修改都按预期工作,我能够在inappbrowser上显示相机插件并获取图像,并在关闭时触发插件的exit
事件。
以下任务现在正在运行:
但是如果我想再次打开inappbrowser(不重新启动应用程序),子视图会打开,但不显示任何内容,只是一个空白页面。当我重新启动应用程序时它会再次运行,但每次关闭应用程序后打开inappbrowser只会显示一个空白屏幕。
我怀疑有一些残留的问题是导致问题的原因。
我在这里看到了两种可能的解决方案:
我不知道如何实施。
有人可以帮助我或指出可能的解决方案的总体方向。
p.s:我知道这不是inappbrowser的预期行为,因为它想要调用本机api是不可能的,但我需要这样做。没有选择iframe或关闭inappbrowser来获取相机。
答案 0 :(得分:2)
我明白了!您必须修改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的顶部打开并将图像传递给它。