[英]PhoneGap Camera , Cannot read property 'getPicture' of undefined
[英]Phonegap build - Uncaught TypeError: Cannot read property 'getPicture' of undefined
APP
我正在尝试创建一个带有照片的简单应用,正在测试phonegap版本
应用加载后,我会收到一个控制台日志,上面写着deviceready
设备准备就绪时会记录该日志
问题
当我单击按钮启动相机时,出现控制台错误:
Uncaught TypeError: Cannot read property 'getPicture' of undefined
JS / HTML
<button onclick="app.takePicture();">Take Picture</button>
<script type="text/javascript" src="phonegap.js"></script>
<script>
var app = {
// Application Constructor
initialize: function() {
this.bindEvents();
},
// Bind Event Listeners
//
// Bind any events that are required on startup. Common events are:
// 'load', 'deviceready', 'offline', and 'online'.
bindEvents: function() {
document.addEventListener('deviceready', this.onDeviceReady, false);
},
// deviceready Event Handler
//
// The scope of 'this' is the event. In order to call the 'receivedEvent'
// function, we must explicity call 'app.receivedEvent(...);'
onDeviceReady: function() {
app.receivedEvent('deviceready');
},
// Update DOM on a Received Event
receivedEvent: function(id) {
var parentElement = document.getElementById(id);
var listeningElement = parentElement.querySelector('.listening');
var receivedElement = parentElement.querySelector('.received');
listeningElement.setAttribute('style', 'display:none;');
receivedElement.setAttribute('style', 'display:block;');
console.log('Received Event: ' + id); // <-- this works ok
},
takePicture: function() {
navigator.camera.getPicture( function( imageURI ) {
alert( imageURI );
},
function( message ) {
alert( message );
},
{
quality: 50,
destinationType: Camera.DestinationType.FILE_URI
});
}
};
app.initialize();
</script>
我也尝试了cordova.js
但cordova.js
同样的问题。
我已经看过前面提到的这个问题,但找不到解决方法,有没有? 有一个更好的方法吗?
想通了,尽管找不到任何地方记录在案!
确保将其添加到config.xml
文件中:
<plugin name="org.apache.cordova.camera" spec="0.3.6" source="pgb" />
根据我的收集,这基本上可以创建navigator
对象
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.