使用 phonegap 下载文件时,当互联网关闭时 - 应用程序挂起并崩溃。我收到以下错误:
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFDictionary setObject:forKey:]: attempt to insert nil value (key: body)' * First throw call stack: (0x35b4c88f 0x33770259 0x35b4c789 0x35b4c7ab 0x35ab968b 0x56a7f 0x57f8d 0x34f9dc29 0x34ef56d9 0x34ef56a3 0x34f9ddfb 0x3189dcb5 0x318034b7 0x318031a3 0x318030d9 0x35b20ad3 0x35b20335 0x35b1f045 0x35aa24a5 0x35aa236d 0x3383d439 0x3327acd5 0x28d9f 0x28d60) terminate called throwing an exception(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');
}
当我断开与 Internet 的连接时,我应该收到以下错误:由于 Internet 连接丢失,下载未完成。请连接到 Internet 并重新下载。
当互联网关闭时,在main.m文件中切换到 Objective-c并卡在这一行:
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 坦纳