On Mar 19, 2014, at 7:29 PM, patrick machielse <[email protected]> wrote:

> We are working on a sandboxed application that keeps track of a large number 
> of files through security scoped URLs. To access the files we carfully 
> balance our calls to startAccessingSecurityScopedResource / 
> stopAccessingSecurityScopedResource:
> 
> [url startAccessingSecurityScopedResource]
> /* do some work */
> [url stopAccessingSecurityScopedResource]
> 
> 
> All was fine until we needed to start accessing the files from multiple 
> threads simultaneously. According to the documentation:
> 
> "When you call the stopAccessingSecurityScopedResource method, you 
> immediately lose access to the resource in question (even if you have 
> previously called startAccessingSecurityScopedResource more than once)."
> 
> Thus, as soon as 1 thread executes its 'stopAccessingSecurityScopedResource', 
> all access in other threaded code blocks is lost.
> 
> It seems that we must design our own bookkeeping around security scoped urls, 
> make sure we don't manage resource access directly in our frameworks, and 
> hope no 3rd party frameworks call stopAccessingSecurityScopedResource behind 
> our backs. We find this API design disappointing (to say the least), it's as 
> if we need to call retain / release *and also* manage the retain count 
> ourselves...
> 
> 
> Sandboxing is a good idea in theory, but the implementation has been kicking 
> sand (.) in our faces for a while now.
> 
> Did we miss some hidden feature? Did anyone design a re-usable solution for 
> accessing security scoped resources from multiple threads?
> 
> We'd be grateful for any ideas!
> 
> patrick

Have you tried using CFURLStartAccessingSecurityScopedResource instead of 
-startAccessingSecurityScopedResource? This is what the documentation has to 
say about it:

"Calls to the CFURLStartAccessingSecurityScopedResource function (or its Cocoa 
equivalent) are nestable on a per-process basis. This means that if your app 
calls the start method on a URL twice, to fully relinquish access to the 
referenced resource you must call the corresponding stop method twice."

Of course, it also claims that the Cocoa method does this, so who knows.

Charles


_______________________________________________

Cocoa-dev mailing list ([email protected])

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 [email protected]

Reply via email to