title: Reusing Apple Sandbox security-scoped bookmarks
body: <p>I am creating a application which is reading files outside the application sandbox. I need the user's permission to read these files and I have got the security-scoped bookmarks to work, by making the user pick the path in a <code>NSOpenPanel</code>.</p>
  
  <p>My problem is that I don't want the user to give me permission every time the application accesses the same path. I am saving the bookmarks in the <code>NSApplicationSupportDirectory</code> folder.</p>
  
  <p>This works fine until the user restarts the computer, then it seems like the saved bookmarks become invalid. The bookmark data looks completely fine when loaded from the disk, but the application requires new security-scoped bookmarks to read the files even though the application is using a bookmark  for the path which worked before the restart.</p>
  
  <p>I am creating the bookmarks like this: </p>
  
  <pre><code>NSData * bookmark  = [url bookmarkDataWithOptions:NSURLBookmarkCreationWithSecurityScope includingResourceValuesForKeys:nil relativeToURL:nil error:&amp;err];
  NSURL* bookmarkUrl = [NSURL URLByResolvingBookmarkData:bookmark options:NSURLBookmarkResolutionWithSecurityScope relativeToURL:nil bookmarkDataIsStale:&amp;isStale error:&amp;err]
  </code></pre>
  
  <p>I am checking if the bookmark is accessible with the following:</p>
  
  <pre><code>[url startAccessingSecurityScopedResource];
  [[NSFileManager defaultManager] contentsOfDirectoryAtURL:url includingPropertiesForKeys:nil options:NSDirectoryEnumerationSkipsHiddenFiles error:&amp;err]
  
  if (err &amp;&amp; err.code == NSFileReadNoPermissionError)
  {
      NSLog(@"No URL access");
      res = NO;
  }
  else if(err)
  {
      NSLog(@"URL validate unexpected error:%@", err);
      res = NO;
  }
  
  if (res)
  {
      //Bookmark works!
  }
  [url stopAccessingSecurityScopedResource];
  </code></pre>
  
  <p>This works as long as I don't restart the Mac. I can quit the application and start it again and my bookmarks still work. But as soon as the Mac is restarted I get the <code>NSFileReadNoPermissionError</code> error even though I am using the saved bookmark that worked before I restarted.</p>
  
  <p>Is there a way to create a bookmark that works when the Mac has been restarted?</p>