2

My app reads iTunes' XML Library file under

/Users/username/Music/iTunes/iTunes Music Library.xml

However, if the iTunes Library is stored on a different hard disk, so will this file. The sandbox doesn't allow me to access this file, unless the user grants it.

This is done using a NSOpenPanel.

However, now I'd have to ask the user for permission to access this file each time he opens up the app, which is pretty annoying.

Is there a way to permanently grant access to a specific file?

EDIT

For example, if you open a file in another app, if you quit it the app will open the same file again. Something like this would be useful.

4

1 回答 1

5

您需要的是使用安全范围的书签。您需要做的概述是:

  1. 检查您是否有保存的书签(见下文),如果有,请激活它。完毕。
  2. 让用户使用NSOpenPanel
  3. 获取返回的 URL 并将其作为安全范围的书签保存到磁盘 - 您将其保存在容器中的某个位置,这NSUserDefaults是一种选择。

而已。您需要阅读Apple 的文档以了解详细信息。

于 2013-05-30T19:16:49.983 回答