Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Communicate between finder sync extension and XPC

I am working on a Finder Sync Extension for OS X and want to use a background XPC service.

I can start in the main app and have it launch the XPC and run correctly but nothing happens when I attempt to access it from the Finder Sync. both the finder sync and the XPC are their own bundles so that may be the reason why. What I am wanting is for the finder sync to talk to the XPC about the status of the files and the main app to talk to both the finder sync and XPC about the list of folders to watch.

Has anyone had any luck with this? Is there a better way for a on demand background service? Is it possible to talk between two XPC services?

like image 381
utahwithak Avatar asked Oct 18 '14 05:10

utahwithak


2 Answers

I had stubbornly ignored utahwithak's answer and tried to get it to work anyway. I eventually had to ask a similar question on Apple Developer Forums and finally received a definitive answer on why connecting the Finder Sync Extension to an embedded XPC service is not a viable system design.

Essentially:

  • Finder Sync Extension essentially behaves like a third party app in that it does not have the same scope as the host app to be able to establish an XPC connection with the embedded XPC service.
  • utahwithak's answer is correct in that in order to allow the Finder Sync Extension to communicate with the XPC service, it needs to be an XPC login item. However there are some caveats to this:

    • This seems to be an accidental feature. Not sure if it's something that might eventually be fixed/removed
    • The XPC will have to be always running even if it doesn't need to, by virtue of being an login item
    • If it's a login item, the user will need to explicitly opt in for this feature and be able to opt out.

Source:

  • Establishing an NSXPCConnection from a Finder Sync Extension to an XPC Service
like image 61
Bryant Balatbat Avatar answered Oct 05 '22 10:10

Bryant Balatbat


Working with some Apple Engineers they realized this was a problem and suggested using a LoginItem until a better solution is in place.

So, it is sort of an XPC service, just one that constantly runs. XPC communication is available to both extension and host app.

It works, although it is not the most ideal solution. I recommend the apple sample project that deals with XPC login items for an example of how to get this working.

like image 35
utahwithak Avatar answered Oct 05 '22 12:10

utahwithak