I transfer data between a safari extension app and MacOS app by using Distributed Notification Center.
I use DistributedNotificationCenter.default().addObserver
with a specific notification name and I post a notification from the MacOS App using the same name DistributedNotificationCenter.default().postNotificationName
I keep getting attempt to post distributed notification 'nameofnotification' thwarted by sandboxing.
I saw in the apple documentation that
Sandboxed apps can send notifications only if they do not contain a dictionary. If the sending application is in an App Sandbox, userInfo must be nil.
My user Info is not nil, but this worked perfectly on previous versions of Mac. What am I missing ? Is this relatively new ?
What’s the alternative to communicate between extension and app? Would an XPC service work ?
UPDATE
I have implemented an XPC Service following apple's documentation, but when I call it from the safari extension I get this error Couldn’t communicate with a helper application.
I can call it without any problems from the application that's embedding The XPC Service.
I have tried to :
- copy the service to the extension's
Contents/XPCServices
- add an app group, and use
let connectionXPC = SXPCConnection.init(serviceName:"XXXXXXX.com.bundlename.XPCService")
instead of justlet connectionXPC = NSXPCConnection.init(serviceName: "com.bundlename.XPCService")
where XXXXXXX is the app group.
Any idea on how to properly use The XPC Service from the extension app, or any other way to communicate and send data between sandboxed extension and app.