Mac App Store for sandboxing and bookmarking with protected area up to 10.7.3

I need my isolated application to open an open file again after restarting the application. Apple provides security- NSURLBookmarkCreationWithSecurityScope bookmarks with the NSURLBookmarkCreationWithSecurityScope and NSURLBookmarkResolutionWithSecurityScope in NSURL bookmark creation and removal methods. However, these flags / parameters are only suitable for 10.7.3 or later and cause the application to crash before 10.7.3.

How do I handle saving / reopening a bookmark file from 10.6 to 10.7.3 in an isolated application?

-

NEXT: see my answer below. The problem was not caused by using NSURLBookmarkCreationWithSecurityScope , but using methods to start and stop bookmarks in the security area.

+6
source share
1 answer

It turns out that using NSURLBookmarkCreationWithSecurityScope does not cause problems with 10.7 - 10.7.2. What causes the failure is -[NSURL startAccessingSecurityScopedResource]: which is not supported until 10.7.3. Therefore, you need to wrap calls to this method (and the corresponding stop method) with an OS check or a response to a request. I tested that the bookmark still works in 10.7.1 unless you call the start / stop.

Here is a code snippet for using respondsToSelector to help anyone else working with this problem:

Use this to start using:

 if([bookmarkFileURL respondsToSelector:@selector(startAccessingSecurityScopedResource)]) { // only supported by 10.7.3 or later [bookmarkFileURL startAccessingSecurityScopedResource]; // start using bookmarked resource } 

And this is to stop using:

 if([bookmarkFileURL respondsToSelector:@selector(stopAccessingSecurityScopedResource)]) { // only supported by 10.7.3 or later [bookmarkFileURL stopAccessingSecurityScopedResource]; // stop using bookmarked resource } 
+9
source

Source: https://habr.com/ru/post/924134/


All Articles