分布式通知不再适用于 Catalina

Distributed notification no longer working in Catalina

我使用分布式通知中心在 Safari 扩展应用程序和 MacOS 应用程序之间传输数据。 我使用 DistributedNotificationCenter.default().addObserver 和特定的通知名称,我 post 来自 MacOS 应用程序的通知使用相同的名称 DistributedNotificationCenter.default().postNotificationName

我不断收到 attempt to post distributed notification 'nameofnotification' thwarted by sandboxing.

我在苹果文档中看到

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.

我的用户信息不是零,但这在以前的 Mac 版本上运行得很好。我错过了什么?这是相对较新的吗?

扩展程序和应用程序之间通信的替代方案是什么? XPC 服务可以工作吗?

更新

我已经在 apple's documentation 之后实现了一个 XPC 服务,但是当我从 safari 扩展程序调用它时,我得到了这个错误 Couldn’t communicate with a helper application. 我可以从嵌入 XPC 的应用程序中毫无问题地调用它服务。

我试过:

关于如何从扩展应用正确使用 XPC 服务的任何想法,或任何其他在沙盒扩展和应用之间通信和发送数据的方式。

在这种情况下,XPC 将不起作用。与新型 Safari 扩展的通信应通过 SFSafariExtensionHandler 子类执行。

建议通过Xcode相应模板创建Safari Extension,所有重要设置、Info.plist字段和基础设施都将为您设置。

请查看官方文档中的详细信息 Building a Safari App Extension