On 11 May, 2013, at 09:50 , Markus Spoettl <ms_li...@shiftoption.com> wrote:

>> NSError *error = nil; NSURLBookmarkCreationOptions options =
>> NSURLBookmarkCreationSuitableForBookmarkFile |
>> NSURLBookmarkCreationWithSecurityScope; NSData *bookmarkData = [self.url
>> bookmarkDataWithOptions:options includingResourceValuesForKeys:nil
>> relativeToURL:nil error:&error];
> 
> Have you tried using just NSURLBookmarkCreationWithSecurityScope as options?

When I do that, the bookmarkData gets created. I then found that after loading 
the data back in when running the app again, then if I wanted to use the URL, 
[userBookmark.url startAccessingSecurityScopedResource] returned NO. However, 
it turns out that I was not reading the data back in properly. I had written 
this:

    self.url = [NSURL URLByResolvingBookmarkData:urlData
                                                   
options:NSURLBookmarkResolutionWithoutUI
                                             relativeToURL:nil
                                       bookmarkDataIsStale:&bookmarkIsStale
                                                     error:&error];

Turns out had overlooked that another option needs to be passed in:

    self.url = [NSURL URLByResolvingBookmarkData:urlData
                                                   
options:NSURLBookmarkResolutionWithoutUI | 
NSURLBookmarkResolutionWithSecurityScope
                                             relativeToURL:nil
                                       bookmarkDataIsStale:&bookmarkIsStale
                                                     error:&error];

Duh.

So, it looks like it is working. Except: now, if the file is moved from where 
it was when the bookmark data was created, it is no longer found. When passing 
in NSURLBookmarkCreationSuitableForBookmarkFile as an option in the non 
sandboxed version this does retain access to the file when the file is moved. 
Neither do the documents suggest that 
NSURLBookmarkCreationSuitableForBookmarkFile and 
NSURLBookmarkCreationWithSecurityScope are mutually exclusive options. The 
question then remains, are they mutually exclusive? —Thus making bookmarks in 
sandboxed apps considerably less flexible than in non-sandboxed apps.) Or 
should this be possible but something else is preventing this from working?

- António


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to