Access to the same file after restart in the sandbox

坚强是说给别人听的谎言 提交于 2019-12-11 04:03:12

问题


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.


回答1:


What you need is to use security scoped bookmarks. The outline of what you need to do is:

  1. Check if you have a saved bookmark (see below), if so activate it. Done.
  2. Have the user select a file/folder using NSOpenPanel
  3. Take the URL that is returned and save it to disk as a security scoped bookmark - you save it somewhere in your container, your NSUserDefaults is one choice.

That's it. You need to read Apple's documentation to understand the details.



来源:https://stackoverflow.com/questions/16842316/access-to-the-same-file-after-restart-in-the-sandbox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!