如何在沙盒Mac应用程序中跟踪用户批准的访问路径?

时间:2021-02-25 02:44:41

How can I tell which paths have been granted access by the user? I know that with NSOpenPanel, the sandbox is automatically expanded to allow access to the directory the user chooses. Is this information stored anywhere so I can know whether I need to throw up an NSOpenPanel or not?

如何判断用户已授予哪些路径访问权限?我知道,使用NSOpenPanel,沙箱会自动扩展,以允许访问用户选择的目录。这些信息是否存储在任何地方,以便我知道是否需要抛出NSOpenPanel?

Or do I need to track it locally in NSUserDefaults or something?

或者我是否需要在NSUserDefaults中本地跟踪它?

2 个解决方案

#1


2  

You are responsible to store already-granted paths using the Secure Bookmarks, read NSURL documentation.

您有责任使用安全书签存储已授予的路径,请阅读NSURL文档。

If you need to access to a path check if you have it on secured bookmarks (stored for example inside NSUserDefaults) if you have reuse it otherwise show the open panel

如果您需要访问路径,请检查您是否拥有安全书签(例如存储在NSUserDefaults内),如果您已重新使用它,否则显示打开的面板

#2


1  

If you need to know whether the current execution of your app can access a particular path you can call access - see the unix man pages section 2. You can test for read, write and execute access, and the result reflects the current sandbox.

如果您需要知道应用程序的当前执行是否可以访问特定路径,您可以调用访问权限 - 请参阅unix手册页第2节。您可以测试读取,写入和执行访问权限,结果将反映当前的沙箱。

If you want to preserve access between executions of your app then you need to create security scoped bookmarks and stored them in user defaults or some other file.

如果要保留应用程序执行之间的访问权限,则需要创建安全范围的书签并将其存储在用户默认值或其他文件中。

#1


2  

You are responsible to store already-granted paths using the Secure Bookmarks, read NSURL documentation.

您有责任使用安全书签存储已授予的路径,请阅读NSURL文档。

If you need to access to a path check if you have it on secured bookmarks (stored for example inside NSUserDefaults) if you have reuse it otherwise show the open panel

如果您需要访问路径,请检查您是否拥有安全书签(例如存储在NSUserDefaults内),如果您已重新使用它,否则显示打开的面板

#2


1  

If you need to know whether the current execution of your app can access a particular path you can call access - see the unix man pages section 2. You can test for read, write and execute access, and the result reflects the current sandbox.

如果您需要知道应用程序的当前执行是否可以访问特定路径,您可以调用访问权限 - 请参阅unix手册页第2节。您可以测试读取,写入和执行访问权限,结果将反映当前的沙箱。

If you want to preserve access between executions of your app then you need to create security scoped bookmarks and stored them in user defaults or some other file.

如果要保留应用程序执行之间的访问权限,则需要创建安全范围的书签并将其存储在用户默认值或其他文件中。