2012-12-21 21 views
0

我使用下面的代碼由所述navigator.camera.getPicture API調用:PhoneGap的2.2的moveTo()失敗給exec回調

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的時間。

回答

0

只是想嘗試一個瘋狂的猜測這一個。我的猜測是,由於成功回調的異步特性,有時由於線程的不可預測性,成功函數尚未定義。嘗試將moveSuccess2函數的聲明移至其聲明總是在調用moveTo函數之前完成的地方。這可能意味着聲明爲gotPicture函數之外的函數,或者聲明爲您的錯誤處理程序之類的匿名函數,或者在您調用moveTo之前聲明它。