使用phonegap下载文件时,当互联网关闭时 - 应用程序挂起并崩溃。我收到以下错误:
*由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:' - [__ NSCFDictionary setObject:forKey:]:尝试插入nil值(键:body)' * 第一次抛出调用堆栈: (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 Tanna
答案 0 :(得分:1)
以下是phonegap 2.5
的修复方法感谢我的同事:)
PS:这些错误和其他几个错误列在Phonegap for iOS的Apache页面上。
答案 1 :(得分:0)
您不能将nil
值设置为字典对象。如果您希望占位符没有值,请使用[NSNull null]
,这会创建单例NSNull
的实例。它在尝试为键body
定义对象时崩溃。如果您有权访问该代码,请尝试try .... catch
以阻止其尝试nil
,可能是默认值。
没有代码,这只是对该错误消息的猜测。