一个拍照上传的功能。执行plus.camera.getCamera().captureImage,拍照完成后回调函数老是不能执行。后来调试发现,打开相机的时候,当前页面的webview 被关闭重新打开了。请问是代码写的不对吗?有什么解决办法?
js代码如下
var agencyLongitude;
var agencyLatitude;
var customer_id;
var plan_id;
var visitPhotos;
var state;
var customer_name;
var company_name;
var area_name;
var address;
var customer_phone;
var photoImgs = new Array();
(function(mui, doc, win) {
mui.init();
//上传门头照片
var uploadPhoto = function() {
//从照相机获取图片
// var photoid = this.id;
var photoid = 0;
console.log('photoid=' + photoid);
plus.camera.getCamera(1).captureImage(function(img){
console.log(1);
compressImg(img, function(p){
var wt=plus.nativeUI.showWaiting("照片上传...");
var filename = img.substr(img.lastIndexOf('/') + 1);
mui.post(server.url() + '/commons/ajaxuploadbase64.do',
{fileData:p, fileName: filename},
function(result){
if(result.flag=="0"){
photoImgs[photoid] = result.data[0].filePath;
doc.querySelector('#takePicture').innerHTML = "<img src=\"" + photoImgs[photoid] + "\" width=\"100%\" height=\"100%\"/></img>";
}else{
//outLine("上传失败:"+status);
plus.nativeUI.toast("照片上传失败");
}
wt.close();
},
'json'
);
});
},function(e){
console.log(e.code);
console.log(e.message);
},{});
};
mui.plusReady(function() {
var self= plus.webview.currentWebview();
plan_id = self.plan_id;
customer_id = self.customer_id;
console.log(11112222);
$("#customer_name").html(self.customer_name);
$("#company_name").html(self.company_name);
$("#address").html(self.area_name+self.address);
if(state != '0'){
doc.querySelector("#submitSummary").style.display = 'none';
}else{
doc.querySelector("#submitSummary").addEventListener('tap',submitSummary);
doc.querySelector("#takePicture").addEventListener('tap',uploadPhoto);
}
doc.querySelector("#takePicture").addEventListener('tap',uploadPhoto);
finishLoading();
});
})(mui, document, window);
打开摄像机后,回调函数里的console.log(1)没有执行,反而是 plusReady里面的 console.log(11112222)又执行了一遍。
真机调试的时候试过iphone5s,小米4,都是这个情况