2
votes

I'm trying to delete files inside application folder from my Cocoa application. By enabling Sandbox mode, I'm not able to delete files inside application folder.

This Sandbox mode has some option for enabling Read/Write access to downloads, pictures, movies, music and user selected file.

Before that I enabled Read and Write Access for user selected file and done my deletion using NSOpenPanel. It works fine and deletes files inside application folder but it opens panel every time when I run my app. Here I dont want any user interaction/permission to delete files inside application folder. Is there any solution to delete files with above defined constraints.

1
The files you want to delete are temporarily used and created by your app? So if yes, why not just use a temporary directory ? - Volker
No its not created by my app. I have a third party executable that will create this temporary files. I have to use the content of that temporary files and finally i have to delete after use. - santhosh
@santhosh: How to allow access using NSOpenPanel??? Can you please help me??? - Manthan

1 Answers

2
votes

You need to use Security-Scoped Bookmarks:

Your app’s access to file-system locations outside of its container—as granted to your app by way of user intent, such as through Powerbox—does not automatically persist across app launches or system restarts. When your app reopens, you have to start over. (The one exception to this is for files open at the time that your app terminates, which remain in your sandbox thanks to the OS X Resume feature).