Sandboxed Mac app exhausting security scoped URL resources

后端 未结 2 639
执念已碎
执念已碎 2021-02-04 09:26

I am developing a Mac application that prompts the user for files using the NSOpenPanel. The application is sandboxed (testing on OSX 10.9.4). I noticed that if I open a large a

2条回答
  •  难免孤独
    2021-02-04 09:51

    The behavior you experience is because the security scoped resources are limited:

    NSURL - (BOOL)startAccessingSecurityScopedResource tells

    If sufficient kernel resources are leaked, your app loses its ability to add file-system locations to its sandbox...

    The current limit is roughly what you experienced. See: What are the current kernel resource limits on security-scoped bookmarks?

    To prevent it:

    • only start accessing those SSBs you need at a given time and subsequently stop accessing them
    • start access not files but enclosing folders: ask the user not to choose files but a full folder. This will grant you access to the whole tree beneath that directory
    • on draggingEntered: show a NSOpenPanel with the enclosing directory(ies) to grant access

提交回复
热议问题