在IOS递归调用resolveLocalFileSystemURL来判断文件是否存在时,根本不进resolveLocalFileSystemURL回调方法(成功、失败都不进),该怎么解决呢:
递归方法:
var iteCount = 0;
function iteratorFun(data){
while(iteCount < data.length){
var sender = "";
var content="";
if(data[iteCount].SENDER == loginName){
sender = "self";
content = data[iteCount].CONTENT;
}else{
sender = data[iteCount].SENDER;
content = data[iteCount].SENDER+":"+data[iteCount].CONTENT;
}
var msg = {
sender:sender,
type: data[iteCount].SENDTYPE,
content: content
};
if(""+msg.type != "text"){
judFile(msg,"load","yes",data);
}else{
record.unshift(msg);
iteCount++;
}
}
if(iteCount == data.length){
bindMsgList();
difHeight();
}
}
判断方法:
//判断文件是否存在
function judFile(msg,type,isIterator,data){
var furl = msg.content;
//需要截取文件名
if(furl.indexOf("/") != -1)
furl = furl.substring(furl.lastIndexOf("/")+1,furl.length);
var judurl = "doc";
var type = msg.type;
if(type == "sound")
judurl += "/audio/"+furl;
else{
judurl += "/"+furl;
}
plus.io.resolveLocalFileSystemURL(judurl, function(entry ){
alert("aaaaaaaaaaaa");
if(type == "sound")
msg.content = judurl;
else{
var path=plus.io.convertLocalFileSystemURL(judurl);
path = "file://"+path;
msg.content = path;
}
if(type == "load"){
record.unshift(msg);//数据装载
}else
record.push(msg);
alert(isIterator);
if(isIterator == "yes"){//进行递归
alert("来到了这里!");
iteCount++;
alert(iteCount);
iteratorFun(data);
}else{
bindMsgList();
difHeight();
}
}, function(error){
alert("文件不存在!");
//文件不存在,下载
downFile(msg,type,isIterator,data);
} );
}
stevewuxl (作者)
IOS9+上都没重现到么?
2016-01-04 14:36