0

我正在使用 navigator.camera.getPicture api 调用的以下代码:

function getImageURI(imageURI) {
    //resolve file system for image to move.
    window.resolveLocalFileSystemURI(imageURI, gotPicture, function(error) {onfail(error,'Get Target Image');}); 

function gotPicture(targetImg) {    
    //move the image into the post_(n) directory.
    targetImg.moveTo(Globals.POSTDIR_OBJ,Utils.getImageName(), moveSuccess2, function(error){alert('Move Error')} ); 

        function moveSuccess2(){
            alert('addPicture moveSuccess');

            //update the picture counts in the client and DB.
            Globals.pictCount++;
            updateFilesById();
            setTimeout("Gallery.show()",500);  
        };
    }; //gotPicture 



}; //getImageURI  

问题是大约 30% 的时间没有调用成功或失败回调函数。

移动其实每次都是成功的,但是成功函数执行失败的时间大约有1/3。

4

1 回答 1

0

只是想对这个进行疯狂的猜测。我的猜测是,由于成功回调的异步性质,有时由于线程的不可预测性,尚未定义成功函数。尝试将 moveSuccess2 函数的声明移动到某个地方,它的声明将始终在调用 moveTo 函数之前完成。这可能意味着声明为 gotPicture 函数之外的函数,或者声明为像错误处理程序一样的匿名函数,或者在调用 moveTo 之前声明它。

于 2012-12-22T03:30:01.250 回答