Note that there are some explanatory texts on larger screens.

plurals
  1. POstartAccessingSecurityScopedResource never returns success
    primarykey
    data
    text
    <p>I'm developing a sandboxed Mac App Store app which asks the user where to save files it downloads from elsewhere. I have this code to get the folder from the user (stripping out some error checking):</p> <pre><code>NSOpenPanel* openPanel = [NSOpenPanel openPanel]; [openPanel setAllowsMultipleSelection:NO]; [openPanel setCanChooseDirectories:YES]; [openPanel setResolvesAliases:YES]; NSInteger result = [openPanel runModal]; NSArray* urls = [openPanel URLs]; NSURL* folderURL = [urls objectAtIndex:0]; NSError* error; NSData* bookmakeData = [folderURL bookmarkDataWithOptions:NSURLBookmarkCreationWithSecurityScope includingResourceValuesForKeys:nil relativeToURL:nil error:&amp;error]; _saveFolderBookmark = bookmakeData; </code></pre> <p>and when it comes time to move a file into this folder, I have this code:</p> <pre><code>BOOL isStale; NSError* error; NSURL* saveFolder = [NSURL URLByResolvingBookmarkData:_saveFolderBookmark options:NSURLBookmarkCreationWithSecurityScope relativeToURL:nil bookmarkDataIsStale:&amp;isStale error:&amp;error]; BOOL success = [saveFolder startAccessingSecurityScopedResource]; // Move the file somewhere else NSWorkspace* workspace = [NSWorkspace sharedWorkspace]; NSInteger operationTag; BOOL copied = [workspace performFileOperation:NSWorkspaceMoveOperation source:[[self getDocumentsFolder] path] destination:[saveFolder path] files:[NSArray arrayWithObject:filename] tag:&amp;operationTag]; [saveFolder stopAccessingSecurityScopedResource]; </code></pre> <p>Which is a lot of code to list to say that startAccessingSecurityScopedResource never returns success for me, either immediately after getting the ULR from NSOpenPanel or in a later run, with the bookmark data being saved in NSUserDefaults.</p> <p>In the entitlements file, amongst other items, I have:</p> <pre><code>&lt;key&gt;com.apple.security.files.bookmarks.app-scope&lt;/key&gt; &lt;true/&gt; </code></pre> <p>Is there anything wrong with this code?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload