Reputation: 1819
While downloading a file using phonegap, when the internet goes off - the application hangs and crashes. I am getting the following error:
* 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)
Downloading logic for the file:
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');
}
When I disconnect from the internet I should get the following error: Download was not completed due to lost internet connection. Please connect to the Internet and re-download.
When the internet goes off, the switch to the objective-c is made in the main.m file and it gets stuck at this line:
retVal is 0. and it does not execute NSLog line.
#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;
}
}
Could anyone suggest the possible reason for this?
Thanks, Ankit Tanna
Upvotes: 0
Views: 680
Reputation: 1819
Below is the fix for phonegap 2.5
Thanks to my colleagues :)
PS: These errors and couple of other errors are listed on an Apache Page of Phonegap for iOS.
Upvotes: 1
Reputation: 496
You cannot set a nil
value as a dictionary object. If you want to have a placeholder for no value, use [NSNull null]
, which creates a instance of the singleton NSNull
. It is crashing when it attempts to define the object for the key body
. If you have access to the code, try a try .... catch
to prevent it from attempting nil
, likely a default value.
Without the code, this is just a guess from that error message.
Upvotes: 0