我需要帮助修改本机代码中的 InAppBrowser
I need help modifying the InAppBrowser in native code
这是一个不同的问题,但仍然是关于我原来的问题:
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,我使用修改后的关闭方法:
- (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;
}
}
请记住,我没有 objective c 方面的经验,也不知道自己在做什么,如有任何提示,我将不胜感激。
两种修改都按预期工作,我能够在 inappbrowser 顶部显示相机插件并获取图像并在关闭时触发插件的 exit
事件。
以下任务正在运行:
- 打开inappbrowser
- 从 inappbrowser 触发相机
- 获取图像到 inappbrowser
- 关闭应用程序浏览器
但是如果我想再次打开 inappbrowser(不重新启动应用程序),子视图打开但不显示任何内容,只是一个空白页面。当我重新启动应用程序时它再次工作,但每次关闭应用程序后打开 inappbrowser 时只显示一个空白屏幕。
我怀疑 inappbrowser 的一些残留是导致问题的原因。
我在这里看到 2 种可能的解决方案:
- 在关闭时删除与 inappbrowser 有关的所有内容
- 重新初始化 inappbrowser 并在每次启动时覆盖所有内容
我也不知道怎么实现。
有人可以帮助我或指出可能解决方案的大体方向吗?
p.s.: 我知道这不是 inappbrowser 的预期行为,因为它想要调用本机 api 不可能,但我需要这样。 iframe 或关闭 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 的关闭方法中,您必须添加:
UIView *lastView;
for(UIView *subview in [self.viewController.view subviews]) {
lastView = subview;
}
[lastView removeFromSuperview];
就在 [self.inAppBrowserViewController close];
.
之前
完成,相机现在在 inappbrowser 顶部打开并将图像传递给它。
这是一个不同的问题,但仍然是关于我原来的问题:
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,我使用修改后的关闭方法:
- (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;
}
}
请记住,我没有 objective c 方面的经验,也不知道自己在做什么,如有任何提示,我将不胜感激。
两种修改都按预期工作,我能够在 inappbrowser 顶部显示相机插件并获取图像并在关闭时触发插件的 exit
事件。
以下任务正在运行:
- 打开inappbrowser
- 从 inappbrowser 触发相机
- 获取图像到 inappbrowser
- 关闭应用程序浏览器
但是如果我想再次打开 inappbrowser(不重新启动应用程序),子视图打开但不显示任何内容,只是一个空白页面。当我重新启动应用程序时它再次工作,但每次关闭应用程序后打开 inappbrowser 时只显示一个空白屏幕。
我怀疑 inappbrowser 的一些残留是导致问题的原因。
我在这里看到 2 种可能的解决方案:
- 在关闭时删除与 inappbrowser 有关的所有内容
- 重新初始化 inappbrowser 并在每次启动时覆盖所有内容
我也不知道怎么实现。
有人可以帮助我或指出可能解决方案的大体方向吗?
p.s.: 我知道这不是 inappbrowser 的预期行为,因为它想要调用本机 api 不可能,但我需要这样。 iframe 或关闭 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 的关闭方法中,您必须添加:
UIView *lastView;
for(UIView *subview in [self.viewController.view subviews]) {
lastView = subview;
}
[lastView removeFromSuperview];
就在 [self.inAppBrowserViewController close];
.
之前
完成,相机现在在 inappbrowser 顶部打开并将图像传递给它。