本文介绍了appcelerator 从目录中检索所有文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Ipad 绘画应用程序,我想从特定目录中检索所有文件,并删除最后保存的图像.在 appcelerator 模拟器中,它一切正常,但是当我在 ipad 上运行我的应用程序时,它停在 var fid = dfo.getDirectoryListing();我不知道我做错了什么,因为我知道他将 png 文件保存在 ipad 上的测试文件夹中(使用警报对其进行了测试).

im working on an Ipad paint application and i want to retrieve all files from a specific directory, and delete the last saved image. In the appcelerator simulator it all works perfect, but when i run my application on my ipad it stops at var fid = dfo.getDirectoryListing();I don't know what i'm doing wrong because i know he saves the png files in the test folder on ipad (tested it with alert).

    //going to the folder, this works he shows alert
   var dfo = Titanium.Filesystem.getFile(Titanium.Filesystem.resourcesDirectory + '/test');
        alert(dfo);
        //trying to get all the files, this works on emulator he shows all files. on ipad empty alert
    var fid = dfo.getDirectoryListing();
        alert(fid);
        //application stops here
    fid = fid.splice(1, fid.length - 1);
        alert(fid);
    var lengte = fid.length - 1;

if (lengte != -1) {
    var lengte2 = lengte -1;
     painter.clear();
     painter.setBackgroundImage(parent + '/back.png');
    painter.setBackgroundImage(parent + '/test/' + fid[lengte2]);
    var file = Titanium.Filesystem.getFile(parent + '/test/' + fid[lengte]);
    file.deleteFile();
}
else{
  alert('going back is at his end');
     painter.clear();
     painter.setBackgroundImage(parent + '/back.png');

}

希望有人能帮助我,在此先感谢!

I hope someone can help me, thanks in advance!

推荐答案

您应该将文件保存到 Ti.Filesystem.applicationDataDirectory 而不是资源目录.

you should be saving your files to Ti.Filesystem.applicationDataDirectory not the resources directory.

我认为模拟器允许它,但设备不是出于安全原因..

I think the emulator is allowing it, but the device is not for security reasons..

这篇关于appcelerator 从目录中检索所有文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 05:36