开发者

Mac OS X: Open file in finder + App Sandbox

开发者 https://www.devze.com 2023-03-25 10:20 出处:网络
I try to open a finder windowwhich works fine but every time I do this there is 1 second delay and an error logged.

I try to open a finder window which works fine but every time I do this there is 1 second delay and an error logged.

[[NSWorkspace sharedWorkspace] selectFile:@"Users/[TheUser]/Downloads" inFileViewerRootedAtPath:pathStr];

The log displays:

开发者_开发技巧

__CFPasteboardIssueSandboxExtensionForPath: error for [/Users/TheUser/Downloads/]

Is this normal? I have enabled entitlements and allowed Downloads folder access.


A bit late, but I just stumbled over this as well and found an answer for this. For this warning/error/whatever it is to disappear, you need to have a security scoped URL to the path (and thats the point where it might be tricky for you, because to obtain such an URL, you must use an NSOpenPanel and annoy the use, even though you have the right entitlement for the folder!).

Once you have that security scoped URL, you have to call the startAccessingSecurityScopedResource method and afterwards make your call to NSWorkSpace. Don't forget to call stopAccessingSecurityScopedResource afterwards (you can do it immediately after the selectFile:inFileViewerRootedAtPath: returned) to free up kernel resources and avoid being unable to make more calls to startAccessingSecurityScopedResource.

0

精彩评论

暂无评论...
验证码 换一张
取 消