我需要帮助以本机代码修改InAppBrowser [英] I need help modifying the InAppBrowser in native code

查看:162
本文介绍了我需要帮助以本机代码修改InAppBrowser的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



这是一个不同的问题,但仍与我原来的问题有关:
那里有一个优雅的地方在iOS的内置浏览器中访问相机的方法?
tl; dr:我想在inappbrowser插件(视图层次结构问题)的顶部打开cordova相机插件.

在我的第一个方法(旧问题)没有使我进入任何地方之后,我尝试修改



this is a different question but is still regarding my original problem:
Is there an elegant way to access the camera from the inappbrowser under iOS?
tl;dr: I want to open the cordova camera plugin on top of the inappbrowser plugin(view hierarchy problem)

After my first approach (old question) did not lead me anywhere, I tried to modify the inappbrowser (gitlink). I wanted it to be a subview of the cordova view, which the following code managed to accomplish:

__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];
    }
});

要关闭浏览器,我使用修改后的close方法:

To close the inappbrowser I use my modified close method:

- (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的经验,也不知道自己在做什么,我将不胜感激.

两种修改均按预期方式进行,我能够将相机插件显示在内置浏览器顶部并获取图像,并在关闭时触发插件的exit事件.

现在,以下任务正在运行:

Please keep in mind that I have no experience in objective c and do not really know what I am doing, I will be grateful for any hints.

Both modifications work as expected, I am able to show the camera plugin on top of the inappbrowser and get the image to it and also trigger the exit event of the plugin on closing.

The following tasks are now working:

  • 打开应用程序浏览器
  • inappbrowser中的触发摄像头
  • 将图像添加到浏览器中
  • 关闭浏览器

但是,如果我想再次打开inappbrowser(不重新启动应用程序),则将打开子视图,但不显示任何内容,仅显示空白页面.重新启动应用程序后,它再次起作用,但是在关闭应用程序后每次打开内浏览器时,只会显示一个空白屏幕.
我怀疑该问题的原因可能是内置浏览器的残留物.
我在这里看到2种可能的解决方案:

BUT if I want to open the inappbrowser again (without restarting the app), the subview opens but does not show anything, just a blank page. It works again when I restart the app, but every time the inappbrowser opens after closing the app only shows a blank screen.
I suspect there are some residuals of the inappbrowser which are the cause of the problem.
I see 2 possible solutions here:

  • 在关闭时删除所有与该应用程序无关的东西
  • 重新初始化内置浏览器,并在每次启动时覆盖所有内容

我也不知道如何实现.
有人可以帮我还是指出可能解决方案的一般方向.

I do not know how to implemet either.
Can somebody please help me or point in the general direction of a possible solution.

p.s .:我知道这不是内置浏览器的预期行为,因为它想要使对本机api的调用变为不可能,但是我需要这种方式.不能使用iframe或关闭内浏览器来获取相机.

p.s.: I know that this is not the intended behaviour of the inappbrowser since it wants to make calls to the native api impossible, but I need it this way. Iframes or closing the inappbrowser to get the camera is no option.

推荐答案

我知道了!您必须修改CDVInAppBrowser的show方法:

I figured it out! 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];
    }
});

只需删除注释行,然后在注释行之后添加2.在CDVInAppBrowser的close方法中,您必须添加:

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];

[self.inAppBrowserViewController close];之前.
完成后,摄像头现在会在不带浏览器的顶部打开,并将图像传递给它.

right before [self.inAppBrowserViewController close];.
Done, the camera now opens on top of the inappbrowser and passes the image to it.

这篇关于我需要帮助以本机代码修改InAppBrowser的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆