title: Unable to get app-scoped bookmark for file - OS X sandbox
body: <p>I've been scouring the net and Apple help for some sort of guidance on this and coming up short.  I wonder if anyone has run into a similar situation, or might have some insight into what is (or isn't) happening.</p>
  
  <p>I'm trying to obtain an app-scoped bookmark for a file to be recalled in a later session by the application.  I can confirm that the path itself is properly added to the sandbox after being selected by the user, because I can open (and reopen) it during the session when it is selected.</p>
  
  <p>However, trying to obtain a security-scoped bookmark to access it later isn't working.</p>
  
  <p>Here's what I'm doing:</p>
  
  <pre><code>NSURL *url = [[NSURL alloc] initFileURLWithPath:path];
  NSError *error = nil;
  NSData *bookmarkData = [url
             bookmarkDataWithOptions:(1UL &lt;&lt; 11) //NSURLBookmarkCreationWithSecurityScope
             includingResourceValuesForKeys:nil
             relativeToURL:nil
             error:&amp;error];
  [url release];
  </code></pre>
  
  <p>I've tried it both with <code>url</code> generated from the string <code>path</code> as well as just testing it with, for instance, the result of the NSSavePanel's <code>URL</code>.  (The string <code>path</code> is, for legacy reasons, the one I'd like to be able to use.)</p>
  
  <p>I'm having to use the value for <code>bookmarkDataWithOptions</code> instead of the constant because, for reasons of some other legacy code, I'm forced to compile with the 10.6 SDK where <code>NSURLBookmarkCreationWithSecurityScope</code> isn't available.</p>
  
  <p>I can confirm that path points to the file in question as "/Users/me/Documents/document.ext", and that the <code>NSURL</code> seems to initialize properly (or at least reflects that same path).</p>
  
  <p>The application includes the entitlement <code>com.apple.security.files.bookmarks.app-scope</code>.</p>
  
  <p>Anyway, this doesn't work. That code results in both a <code>bookmarkData</code> of 0x0 and an <code>error</code> of 0x0, and the console shows: <code>ScopedBookmarkAgent: Failed to retrieve app-scope key, aborting.</code></p>
  
  <p>If I change <code>relativeToURL</code> to be <code>url</code> instead of <code>nil</code> and change the entitlement to <code>com.apple.security.files.bookmarks.document-scope</code>, then it seems to work properly — that is, <code>bookmarkData</code> at least gets a non-zero value and no error gets logged.  But I'm pretty sure that's not what I want (i.e., a document-scope bookmark).</p>
  
  <p>Is there something obvious I'm doing wrong?</p>