App sandbox: how to allow XPC service to read file that user opened in parent app?

前端 未结 1 1465
栀梦
栀梦 2020-12-14 03:57

I have a simple Cocoa image preview app. The user selects a file using an NSOpenPanel and the app generates a preview image using the Quick Look API.

I\

相关标签:
1条回答
  • 2020-12-14 04:32

    I'm not 100% sure but I think Apple recommends passing an NSFileHandle to the XPC process in this case. That way, the XPC process can access the file's contents but does not need to know the file's URL.

    Edit: This thread in the Apple Developer Forums is helpful. The recommendation is to create a normal (not security-scoped) bookmark for the URL of the file. This bookmark can then be passed to the XPC process and accessed by it.

    0 讨论(0)
提交回复
热议问题