沙盒化时如何访问另一个文件引用的文件(应用程序商店) [英] How do I gain access to files referenced by another file when sandboxed (app-store)

查看:27
本文介绍了沙盒化时如何访问另一个文件引用的文件(应用程序商店)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,如果我有一个 XML 文件(从另一个应用程序导出,因此我无法控制内容)将不同文件夹中的图像引用到 XML 文件,则在用户浏览之前我无法读取图像给他们使用我的应用程序.

For example if I have an XML file (exported from another app, so I have no control over the contents) that references images in different folders to the XML file, I am not able to read the images until the user has browsed to them using my app.

我可以通过让他们浏览到更高级别的文件夹(甚至浏览到/")来绕过它,但是告诉用户我无法访问/path/to/file,你现在可以浏览一下吗,我可以打开它?"

I can get around it by making them browse to a higher level folder (even browsing to "/"), but it seems a bit crap to be telling the user "I can't access /path/to/file, can you please browse to it now, so I can open it?"

有没有更好的解决方案?是不是有什么办法可以显示类似AppX 正在尝试从/Users/UserX/FolderX 读取,你会授予权限吗?"这样的提示吗?

Are there any better solutions to this? Isn't there some way to show a prompt like "AppX is trying to read from /Users/UserX/FolderX, will you grant permission?"

推荐答案

在此处查看我的问题和答案:应用沙盒:文档范围的书签无法解析;不返回任何错误

See my question and answer here: App Sandbox: document-scoped bookmark not resolving; not returning any error

我将集合范围的书签嵌入到我的 XML 文件中.

I'm embedding collection-scoped bookmarks into my XML files.

更新

鉴于您无法控制输入 XML 格式的规范,让您的应用访问 XML 中指定文件的唯一方法是让用户选择该文件或文件的父目录之一NSOpenPanel.如果 XML 包含多个文件引用,您可以让用户授予对包含所有这些文件的目录的访问权限.

Given the specification that you have no control over the input XML format, the only way to get access for your app to a file specified in the XML is by having the user select that file or one of the file's parent directories in an NSOpenPanel. If the XML contains multiple file references, you can have the user grant access to a directory that contains all of them.

没有办法绕过请求许可,因为这会破坏沙箱的目的.如果您的应用可以绕过用户的直接许可,那么恶意软件也可以.但是,一旦获得访问权限,您就可以为每个文件创建一个安全范围的书签,这样您就无需多次向用户询问权限.

There is no way around asking permission, since that would defeat the purpose of sandboxing. If your app could get around the user's direct permission, so could malware. Once given access, though, you can create a security-scoped bookmark to each file so you don't need to ask the user for permission multiple times.

更新 2

回答您评论中的问题,您可以通过以下方式让用户更轻松地进行对话:

Answering the question in your comment, you can make the dialog easier for the user with the following:

[openPanel setMessage:@"Click 'OK' to allow access to files contained in the selected directory"];
[openPanel setDirectoryURL:[NSURL fileURLWithPath:pathFromTheXMLFile]];

这是 关于NSSavePanel 的文档(NSOpenPanel 继承自它,上面的属性在那里定义).

Here's the documentation on NSSavePanel (NSOpenPanel inherits from it, and the properties above are defined there).

这篇关于沙盒化时如何访问另一个文件引用的文件(应用程序商店)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆