简体   繁体   中英

Distributed notification no longer working in Catalina

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 just let 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.

The XPC will not work in this case. Communication with new type Safari Extensions should be performed via SFSafariExtensionHandler subclass.

It is recommended to create Safari Extension via Xcode corresponding template, all important settings, Info.plist fields, and infrastructure will be set up for you.

Please see good documented details at official Building a Safari App Extension

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM