Forum Navigation
You need to log in to create posts and topics.

Sandbox 'safe' open recent menu

Posted by: artlythere <artlythere@...>

Seems Bookmarks are the only 'sandbox safe' way to have Recent Items in a sandboxed app.

But I have no idea how to implement that. The com.domain.AppsRecentItems plist approach used in the editor and elsewhere does not work in a sandboxed app once you try to recover a file. If you save one to it , you can reopen it, but only during that particular run.

So, I am left wondering how to implement recent items. I could store them in Application Support... all that works I know, but in what manner?
 
I see Bernie's demo, but not sure how to make that work for more than one item?

Then there is the situation of security scoped bookmarks, which I guess factors in once you try to actually re-open a file programmatically?

rc

Found this on a RealBasic forum...

The process goes along this route.
#1 When the user selects/opens a file, you call "CFURLCreateBookmarkData", which returns a CFDataRef. You must specify the const kCFURLBookmarkCreationWithSecurityScope as an option. You then store this data.

#2 When the user then wants to access this file (after the application has been quit and relaunched), you then use "CFURLCreateByResolvingBookmarkData", passing in the CFData from the step above. You must use the constant kCFURLBookmarkResolutionWithSecurityScope as an option.

Once you have a valid CFURL, you then call "CFURLStartAccessingSecurityScopedResource" on that URL. To use a CFURL in RS, you can call CFURLGetFSRef on the CFURL and it'll return a FSRef.

#3 When the user has finished with that resource, you then need to call "CFUrlStopAccessingSecurityScopedResource" otherwise this will cause Kernel leaks (according to Apple's Documentation).

I've tested it with a simple program that stores references to applications and I have it working. Like I say, my code is in trail stage and not very elegant.

Oh and btw, you can only test this with a Sandboxed application, otherwise the calls fail! Took a few minutes to work that one out :)