gpt4 book ai didi

javascript - 仅当应用程序移至后台时才会激活 Cordova 相机

转载 作者:行者123 更新时间:2023-12-03 07:01:32 25 4
gpt4 key购买 nike

我正在尝试为 iPad 应用程序包含 cordova 相机插件,但在使用 navigator.camera 调用相机后,它仅在应用程序转到后台(点击主页按钮)后才显示在屏幕上。但是,只有当我正在监听 webView:shouldStartLoadWithRequest 事件(我将其用作 javascript-Objective C 桥)时,才会发生这种情况。

使用的版本:

  • Cordova :5.4.1
  • iOS 平台/平台特定的 cordova.js:4.1.1
  • Xcode:7.2

设置项目的步骤:

  • cordova 创建pluginTest com.pluginTestpluginTest
  • cd 插件测试
  • cordova平台添加ios
  • cordova 插件添加 cordoba-plugin-camera

为了测试相机,我编辑了由 cordova 生成的 index.js 文件,以便 onDeviceReady 函数如下所示:

onDeviceReady: function() {
app.receivedEvent('deviceready');
alert(navigator.camera);
navigator.camera.getPicture(function(imageData) {
alert('success');
},
function(message) {
alert('fail');
});
}

这似乎工作正常,警报后相机会弹出。

但是在 MainViewController.m 中,如果我正在监听 webView: ShouldStartLoadWithRequest 事件,例如:

-(BOOL) webView:(UIWebView *)webView shouldStartLoadWithRequest: (NSURLRequest *)request navigationType: (UIWebViewNavigationType)navigationType {

NSString* req = [[request URL] absoluteString];
NSLog(req);

return YES;
}

然后,一旦应用程序加载,第一个位置更改是index.html,之后 - 一旦执行 navigator.camera.getPicture - 就会有无限数量的位置更改触发上述方法,并且 url 始终为 '间隙://准备好'。一旦点击主页按钮,请求流就会停止,并且相机会出现。有什么想法为什么会发生这种情况吗?

另外,我必须让我的 MainViewController 符合 UIWebViewDelegate 协议(protocol),以便它实际监听 shouldStartLoadWithRequest 事件,以防我使用 4.1.1 cordova.js。在这种情况下,仅仅遵守 UIWebViewDelegate 协议(protocol)就足以导致问题发生。奇怪的是,如果我使用的是较旧的 cordova 平台 - 特别是 3.9.2 - 那么 CDVViewController 似乎已经在监听 shouldStartLoadWithRequest 事件。无论哪种情况,相机都会在应用程序暂停后显示。

Xcode 中的控制台跟踪显示:

2016-05-04 19:02:51.015 plugTest2[3949:2271226] file:///var/mobile/Containers/Bundle/Application/FE21DCB1-7ADE-4754-80F1- 7055F8E1F450/plugTest2.app/www/index.html
2016-05-04 19:02:51.020 plugTest2[3949:2271226] Resetting plugins due to page load.
2016-05-04 19:02:51.759 plugTest2[3949:2271226] Finished load of: file:///var/mobile/Containers/Bundle/Application/FE21DCB1-7ADE-4754-80F1-7055F8E1F450/plugTest2.app/www/index.html
2016-05-04 19:02:57.149 plugTest2[3949:2271226] gap://ready

在接下来的 4 秒内跟随大约一百个“gap://ready”网址...

2016-05-04 19:03:01.738 plugTest2[3949:2271226] gap://ready
2016-05-04 19:03:02.112 plugTest2[3949:2271226] Snapshotting a view that has not been rendered results in an empty snapshot. Ensure your view has been rendered at least once before snapshotting or snapshot after screen updates.

最佳答案

我知道我迟到了,但今天我度过了艰难的一天试图解决这个问题,我可以解决这个问题,将以下内容添加到我的内容安全策略标签中:

default-src * blob: 'self' gap:

我把你放在上下文中了。这是我的网络应用程序的index.html 中的元标记。

<meta http-equiv="Content-Security-Policy" content="default-src * blob: 'self' gap:; script-src 'self' 'unsafe-inline' (…)/ >

我在 this 中找到了有关该问题的信息文章。正如它所解释的:

“gap://ready file://* : is required to allow the loading of remote content in iOS 10 app”

我希望这对其他人有帮助。

关于javascript - 仅当应用程序移至后台时才会激活 Cordova 相机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37030884/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com