我想包括iPad应用程序的科尔多瓦相机插件,但在使用navigator.camera调用相机之后,它仅在应用程序转到背景(点击主页按钮)。但是,只有在我正在监听webView:shouldStartLoadWithRequest事件时,才会发生这种情况,我将其用作javascript-Objective C桥接。使用科尔多瓦相机只有当应用程序移动到背景时才被激活
版本:
- 科尔多瓦:5.4.1
- iOS平台/平台的具体cordova.js:4.1.1
- 的Xcode 7.2
步骤设置项目:
- cordova create pluginTest com.pluginTest plugin测试
- CD pluginTest
- 科尔多瓦平台添加IOS
- 科尔多瓦插件添加科尔多瓦 - 插件相机
为了测试相机,我编辑了index.js文件,它是由科尔多瓦产生这样onDeviceReady函数看起来像:
onDeviceReady: function() {
app.receivedEvent('deviceready');
alert(navigator.camera);
navigator.camera.getPicture(function(imageData) {
alert('success');
},
function(message) {
alert('fail');
});
}
这似乎工作正常,相机弹出警报后。
但在MainViewController.m,如果我听一个web视图: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总是'gap:// ready'。点击主页按钮后,请求流将停止,相机显示。任何想法为什么会发生这种情况?
此外,我必须让我的MainViewController符合UIWebViewDelegate协议,才能真正监听shouldStartLoadWithRequest事件,以防我使用4.1.1 cordova.js。在这种情况下,只要符合UIWebViewDelegate协议就足以使问题发生。奇怪的是,如果我正在使用一个较老的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
随后约一百名 '差距://准备' 的URL地址在接下来的4数秒
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.
对不起,但它没有为我工作。我没有使用任何框架 - 只是默认的cordova应用程序,所以我的所有脚本都是从文件系统加载的,而且我的CSP元标记上有自我属性。 我最终编写了一个插件来处理shouldStartLoadWithRequest块中的任何内容。 – indGov