How do you allow an XPC service to create a new file based on an NSURL that the user selected from an NSSavePanel?

How do you send an NSURL representing a new file, as returned from an NSSavePanel, to an XPC service such that the service is granted permission to create the file?

I can successfully pass an NSURL to the XPC process if the NSURL represents an existing file. This is documented in Apple's Documentation:

This involves creating bookmark date while passing 0 in as the options. However, if you try to create bookmark data for an NSURL that represents a file that is not yet created, you do not get any bookmark data back and an error is returned instead:

Error Domain=NSCocoaErrorDomain Code=260 
"The file couldn’t be opened because it doesn’t exist."

Simply passing the file path to the XPC process, by way of:

xpc_dictionary_set_string(message, "file_path", url.fileSystemRepresentation);

Does not grant the XPC create/write permissions. Is there an API or trick I'm missing?

Note that the user should be allowed to save and create new files anywhere of their choosing, thus restricting URLs to only those within a group or container shared between the app and service isn't really viable.

Using the latest of everything on macOS with the xpc_session API...

IIRC this works if you pass the security-scoped URL to your XPC service using NSXPCConnection. The NSURL encoder has the smarts requires to transfer the security scope.

I don’t see any way to make that work with the xpc_session API.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

How do you allow an XPC service to create a new file based on an NSURL that the user selected from an NSSavePanel?
 
 
Q