gpt4 book ai didi

javascript - 使用 Phonegap 下载文件时 iOS 应用程序崩溃

转载 作者:行者123 更新时间:2023-11-29 03:50:00 25 4
gpt4 key购买 nike

使用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 0x28d6 0)终止调用抛出异常(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');
}

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

当互联网关闭时,在 ma​​in.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;
}
}

有人可以提出可能的原因吗?

谢谢,安基特·坦纳

最佳答案

以下是针对phonegap 2.5的修复

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

感谢我的同事:)

PS:这些错误和其他几个错误列在 iOS 版 Phonegap 的 Apache 页面上。

关于javascript - 使用 Phonegap 下载文件时 iOS 应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17167874/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com