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

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

问题描述

例如,如果我有一个XML文件(从其他应用程序导出的,所以我有过的内容没有控制),它引用在不同的文件夹中的图像到XML文件,我不能够读取图像,直到用户浏览他们用我的应用程序。

我可以让他们浏览到一个更高级别的文件夹绕过它(甚至浏览到/),但似乎有点废话要告诉用户我无法访问/路径/要/文​​件,可以请你现在浏览到它,所以我可以打开吗?

是否有这个没有更好的办法?是不是有一些方法来显示一个提示,如AppX中试图从/用户读取/ UserX / FolderX,你会准许?


解决方案

请参阅我的问题和答案在这里:<一href=\"http://stackoverflow.com/questions/10259692/app-sandbox-document-scoped-bookmark-not-resolving-not-returning-any-error\">App沙盒:文件作用域加入书签的不是解决;不返回任何错误

我收集嵌入范围的书签到我的XML文件中。

更新

鉴于您对输入的XML格式的无法控制的规范,是通过让用户选择在该文件或文件的父目录中得到您的应用程序访问XML中指定的文件的唯一办法<​​P> NSOpenPanel 。如果XML包含多个文件引用,你可以有一个包含所有这些目录的用户授予访问权限。

有没有办法到处问权限,因为这会破坏沙盒的目的。如果您的应用程序可以得到各地用户的直接权限,所以可能的恶意软件。一旦给定的访问,不过,你可以创建一个安全范围的书签的每个文件,所以你不必请求允许多次用户。

更新2

回答这个问题在您的评论,你可以使对话更容易使用以下用户:

  [openPanel setMessage:@点击'确定',以允许访问包含在所选目录中的文件];
[openPanel setDirectoryURL:[NSURL fileURLWithPath:pathFromTheXMLFile]];

这里的<一个href=\"https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ApplicationKit/Classes/NSSavePanel_Class/Reference/Reference.html#//apple_ref/occ/cl/NSSavePanel\"相对=nofollow>在 NSSavePanel NSOpenPanel 从它继承和上面的属性文件那里定义)。

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.

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?"

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

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

Update

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.

Update 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]];

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

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

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