2013-06-18 59 views
0

使用phonegap下载文件时,当互联网关闭时 - 应用程序挂起并崩溃。我收到以下错误:iOS应用程序使用Phonegap下载文件时崩溃

*终止应用程序由于未捕获的异常 'NSInvalidArgumentException',原因是: ' - [__ NSCFDictionary的setObject:forKey:]:试图插入空值(键:体)' *第一扔调用堆栈: (0x35b4c88f 0x33770259 0x35b4c789 0x35b4c7ab 0x35ab968b 0x56a7f 0x57f8d 0x34f9dc29 0x34ef56d9 0x34ef56a3 0x34f9ddfb 0x3189dcb5 0x318034b7 0x318031a3 0x318030d9 0x35b20ad3 0x35b20335 0x35b1f045 0x35aa24a5 0x35aa236d 0x3383d439 0x3327acd5 0x28d9f 0x28d60) 终止叫做抛出异常(LLDB)

下载逻辑的文件:

if(isOnline){ 
      // alert("DEVICE is ONLINE" + isOnline); 
      try{ 
       filePath = globalPathNew + "/" +name+ "."+fExt; 
       //  alert("SAVING VIDEO AT ------> " + filePath); 


       document.getElementById('PB'+name).style.display = 'block'; 

       document.getElementById('P'+name+'L').innerHTML = ''; 

       document.getElementById('P'+name+'L').innerHTML = 'Downloading...'; 





       ftv.onprogress = function(progressEvent) { 
        console.log("In Progress video"+progressEvent.lengthComputable); 
        if (progressEvent.lengthComputable) { 
         //downloadcompleteStatus = Math.round(100 * (progressEvent.loaded/progressEvent.total)); 
         $("#P" + name + "Progress").text(Math.round(100 * (progressEvent.loaded/progressEvent.total)) + "%"); 
         console.log("------progressEvent if video------->%"+Math.round(100 * (progressEvent.loaded/progressEvent.total))); 
        } else { 
         console.log("------progressEvent else------->%"+Math.round(100 * (progressEvent.loaded/progressEvent.total))); 

        } 
       }; 


       fileObjAbort = ftv; 
       //alert("Video FileObj"+JSON.stringify(fileObjAbort)); 

       ftv.download(
          url, 
          filePath, 
          function(entry) { 

          // alert("download complete: " + entry.fullPath); 
          //          console.log('video entry.fullPath------'+entry.fullPath); 
          //          console.log('video filePath ----'+filePath); 

          changeIsdownloadStatus(filePath, name, 'video'); 

          if(currElementId != '' && currElementId != '' && currElementId != ''){ 
          detailPageView(currElementId,currElementtype,currElementcountNum); 
          } 
          var index = -1; 

          $.each(downloadList, function(key,tempItem){ 
            if(tempItem.elementId == elementId){ 
            index = key; 

            } 
            }); 

          // alert("dw list"+JSON.stringify(downloadList)); 
          if(index != -1){ 
          delete downloadList[index]; 
          downloadList.splice(index,1); 
          } 
          //alert("dw list after Video Splice \n"+JSON.stringify(downloadList)); 
          findNextDownloadItem(name); 


          // alert("DOWNLOADED ------> "); 
          if(currDownload == elementId){ 

          //changeIsdownloadStatus(filePath,name, 'delete'); 

          if(currElementId != '' && currElementId != '' && currElementId != ''){ 
          detailPageView(currElementId,currElementtype,currElementcountNum); 
          } 

          } 


          console.log('*********************Video******************************'); 
          console.log('-->delete element id:'+elementId); 
          console.log('deleteProgressindex Position:'+index); 
          console.log('-->before delete Length Array :'+downloadList.length); 

          console.log('-->before delete Length Array :'+downloadList.length); 
          console.log('***************************************************'); 


          //          playMedia(filePath, name,'video'); 


          // Code added 
          //bhavya getFileSystemRefForWriting(jsonData); 

          deleteProgress(name,elementTitle,isDownloadedFlag,elementAudio,val,filePath); 
          // Code added 
          // getFileSystemRefForWriting(jsonData); 

          }, 
          function(error) { 
          if(error.code != 4 || error.code != '4'){ 
          //alert("Download Error"); 

          jAlert('Download was not completed due to lost internet connection. Please connect to the Internet and re-download.', 'TT'); 
          console.log("download error" + error.source); 
          //          console.log("download error source " + error.source); 
          //          console.log("download error target " + error.target); 
          //          console.log("upload error code" + error.code); 
          } 
          } 
          ); 

      } 
      catch(error) 
      { 
       var txt="There was an error on this page.\n\n"; 
       txt+="Error description: " + err.message + "\n\n"; 
       txt+="Click OK to continue.\n\n"; 
       console.log('in catch block of video------>>>>'+txt); 
      } 


     }else{ 
      jAlert('Please go online to download file.', 'TT'); 
     } 

当我从互联网断开连接时,我应该得到以下错误: 由于网络连接丢失,下载未完成。请连接到互联网并重新下载。

当互联网熄灭,切换到的Objective-C在的main.m文件由它卡在这行:

retVal的是0,它不执行的NSLog行。

#import <UIKit/UIKit.h> 

int main(int argc, char* argv[]) 
{ 
    @autoreleasepool { 
     **int retVal = UIApplicationMain(argc, argv, nil, @"AppDelegate");** 

     NSLog(@"RETURN VALUE ----->: %d ", retVal); 

     return retVal; 
    } 
} 

任何人都可以提出可能的原因吗?

感谢, ANKIT塔纳

+0

你可以提供一些这方面的更多细节。就像下载文件的代码片段一样,或者您在使用Phonegap应用程序中的任何本机插件? – AJS

+0

好吧我会编辑问题并添加下载逻辑。 –

+0

该调用不会进入错误处理函数。 –

回答

0

你不能设置一个nil值作为字典对象。如果你想要一个没有值的占位符,使用[NSNull null],它创建了一个单例NSNull的实例。当它试图为键body定义对象时,它会崩溃。如果您有权访问该代码,请尝试try .... catch以防止其尝试nil,这可能是默认值。

没有代码,这只是来自该错误消息的猜测。

+0

嗨,我已添加下载逻辑。 –

1

下面是PhoneGap的修复2.5

  1. 转到CordovaLib.xcodeproject
  2. 导航到:类>命令> CDVFileTransfer.m
  3. 转到或搜索以下功能: - (的NSMutableDictionary *)createFileTransferError
  4. 之前添加以下行[result setObject:body forKey:@“body”]; if(body == nil)body = @“”;
  5. Voila !!!你在那儿。

感谢我的同事:)

PS:这些错误和几个其他错误都列在的PhoneGap的一个Apache页面的iOS。

+0

谢谢..它工作.. :) –

相关问题