I need my sandboxed app to reopen an opened file after the app is restarted. Apple provides security-scoped bookmarks with the NSURLBookmarkCreationWithSecurityScope and NSURLBookmarkResolutionWithSecurityScope options in the NSURL bookmark creation and resolving methods. However, these flags/options are only good for 10.7.3 or later and cause an app prior to 10.7.3 to fail.
How do I handle retention/reopening of the file bookmark for 10.6 to 10.7.3 in a sandboxed app?
—
FOLLOW-UP: Please see my answer below. The issue was not caused by using NSURLBookmarkCreationWithSecurityScope but by using the security-scoped bookmark start and stop methods.
It turns out using
NSURLBookmarkCreationWithSecurityScopedoes not cause an issue with 10.7 – 10.7.2. What causes the failure is calling-[NSURL startAccessingSecurityScopedResource]:which is not supported prior to 10.7.3. Therefore, you need to wrap calls to this method (and the corresponding stop method) with an OS check or a respondsToSelector check. I tested that the bookmark still works in 10.7.1 as long as you make sure not to call start/stop.Here are some code snippet for using
respondsToSelectorthat will help any others that run in to this problem:Use this to start usage:
And this to stop usage: