StartAccessingSecurityScopedResource never returns success

I am developing a Mac App Store application with a sandbox that asks the user where to save the files that he downloads from other sources. I have this code to get a folder from a user (removing some errors):

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:&error];
_saveFolderBookmark = bookmakeData;

and when the time comes to move the file to this folder, I have this code:

BOOL isStale;
NSError* error;
NSURL* saveFolder = [NSURL URLByResolvingBookmarkData:_saveFolderBookmark
                                              options:NSURLBookmarkCreationWithSecurityScope
                                        relativeToURL:nil
                                  bookmarkDataIsStale:&isStale
                                                error:&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:&operationTag];
[saveFolder stopAccessingSecurityScopedResource];

Which is a lot of code for the list, to say that startAccessingSecurityScopedResource never returns success for me, either immediately after receiving the ULR from NSOpenPanel, or at a later start when bookmark data is stored in NSUserDefaults.

In a file of rights, among other elements, I:

<key>com.apple.security.files.bookmarks.app-scope</key>
<true/>

Is there something wrong with this code?

+5
source share
2

. NSURLBookmarkCreationWithSecurityScope NSURLBookmarkResolutionWithSecurityScope. , .

(, , , URL-, . , , .)

+8

, , Id , (startAccessingSecurityScopedResource YES). , URL, Powerbox, (, ) URL- , . , Powerbox URL- , startAccessingSecurityScopedResource .

0

All Articles