如何使用 App 沙盒应用程序在 MAC 卷中查找文件和文件夹
我正在 MAC(10.9) 上创建一个沙盒应用程序.当应用程序沙盒化关闭时,我可以从任何路径获取文件和文件夹.但是当我启用 App Sand-boxed 时,它不会从任何路径访问任何文件和文件夹.使用 Qt 5.0 关闭 App Sand-boxed 时,从路径(/Volumes/DriveName"或/"等)获取文件和文件夹
I am creating a sand-boxed application on MAC(10.9).When App Sand-boxed is off then i am able to get files and folders from any path. But when I does App Sand-boxed enabled it's not accessing any files and folders from any path. Getting file and folder from path ("/Volumes/DriveName" or "/" etc.) when App Sand-boxed is off using Qt 5.0
// for folders
QStringList folderlist;
QDir curDir = QDir(path);
curDir.setFilter(QDir::Dirs);
QFileInfoList list = curDir.entryInfoList();
for(;<list.size;)
{
QfileInfo fileInfo = list.at(i);
folderList << fileInfo.filePath();
}
// for files
QStringList filelist;
QDirIterator dirIn(path,filterfiles,QDir::AllEnteries);
while(dirIn.hasnext())
{
dirIn.next();
QfileInfo fileInfo = dirIn.fileInfo();
filelist<< fileInfo.filePath();
}
What i do same when App sand-boxed is enabled?
这就是沙箱的意义所在,您只能访问沙箱内的资源.用户可以向沙箱添加文件,但这需要您的应用程序启动文件打开对话框,以便他们可以选择要使用的文件.
That's the point of a sandbox, you can only access resources within the sandbox. A user may add files to the sandbox, but that requires your application to launch a file open dialog box, so they can choose the file they want to work with.
我建议您首先阅读 Apple此处提供文档.