2

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.

Cœur
  • 37,241
  • 25
  • 195
  • 267
santhosh
  • 1,191
  • 4
  • 14
  • 28
  • 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 Feb 12 '14 at 09:31
  • 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 Feb 12 '14 at 11:53
  • @santhosh: How to allow access using NSOpenPanel??? Can you please help me??? – Manthan Jul 27 '15 at 10:16

1 Answers1

2

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).

cacau
  • 3,606
  • 3
  • 21
  • 42
  • I used this Security-Scoped Bookmarks in my application. it works fine until my app terminates. But its not retaining when i relaunch my app. Is there any possibilities to retain this bookmark when i relaunch my app without using powerbox? – santhosh Feb 14 '14 at 15:07
  • I had retained this bookmark also in app relaunch by using nsuserdefaults.Thanks for your help. Also i referred this link http://stackoverflow.com/questions/18711049/creating-a-security-scope-bookmark-for-a-file-from-one-of-a-directory-containing – santhosh Feb 15 '14 at 06:08