How can safari extension communicate with native app

Hello all

Official developer guide https://developer.apple.com/library/archive/documentation/Tools/Conceptual/SafariExtensionGuide/CommunicatingwithyourOSXApplication/CommunicatingwithyourOSXApplication.html#//apple_ref/doc/uid/TP40009977-CH23 doesn't provide enough information about communicating with native OS X applications.


I've seen this WWDC video https://developer.apple.com/videos/play/wwdc2016/214/

in this video i have seen that safari extension could pass message from web page to containing app (Notebook app)


Can i get sources from extension which send messages to notebook app?


Thanks

Replies

Far as I understand (as always might be wrong), Apple does not support this direction at all (with some limitations, you can message your extension from your container app, though).


To send messages from the extension to the container, you need to open your own communication channel. Depending on your needs, the plain old Distributed Objects might work; or you might get down to sockets; or, alas, in a pretty limited circumstances I've just tried to describe in the thread https://forums.developer.apple.com/thread/62932 you can use XPC.


(Is there a way to get a link to a particular post, not to whole thread? Perhaps today's my dumb day, but I can't see anything in there...)

P.S. Or perhaps — to effectively send a message from the extension to the container — one might write to a shared user defaults group (as the documentation suggests), and observe defaults changes at the container side.


Sounds a bit at the crazy side, but possibly might be efficient enough for all practical purposes? No idea, I've never tried 🙂