简体   繁体   English

分布式通知不再适用于 Catalina

[英]Distributed notification no longer working in Catalina

I transfer data between a safari extension app and MacOS app by using Distributed Notification Center.我使用分布式通知中心在 safari 扩展应用程序和 MacOS 应用程序之间传输数据。 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我使用DistributedNotificationCenter.default().addObserver和特定的通知名称,并使用相同的名称从 MacOS 应用程序发布通知DistributedNotificationCenter.default().postNotificationName

I keep getting attempt to post distributed notification 'nameofnotification' thwarted by sandboxing.我不断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.如果发送应用程序在应用沙盒中,则 userInfo 必须为零。

My user Info is not nil, but this worked perfectly on previous versions of Mac.我的用户信息不是零,但这在以前版本的 Mac 上运行良好。 What am I missing ?我错过了什么? Is this relatively new ?这是相对较新的吗?

What's the alternative to communicate between extension and app?在扩展程序和应用程序之间进行通信的替代方法是什么? Would an XPC service work ? XPC 服务会起作用吗?

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.我已经按照苹果的文档实现了一个 XPC 服务,但是当我从 safari 扩展中调用它时,我收到此错误Couldn't communicate with a helper application. I can call it without any problems from the application that's embedding The XPC Service.我可以从嵌入 XPC 服务的应用程序中毫无问题地调用它。

I have tried to :我试图:

  • copy the service to the extension's Contents/XPCServices将服务复制到扩展的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.添加一个应用程序组,并使用let connectionXPC = SXPCConnection.init(serviceName:"XXXXXXX.com.bundlename.XPCService")而不是let connectionXPC = NSXPCConnection.init(serviceName: "com.bundlename.XPCService")其中 XXXXXXX 是应用程序组。

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.关于如何从扩展应用程序正确使用 XPC 服务的任何想法,或任何其他方式在沙盒扩展程序和应用程序之间进行通信和发送数据。

The XPC will not work in this case.在这种情况下 XPC 将不起作用。 Communication with new type Safari Extensions should be performed via SFSafariExtensionHandler subclass.与新型 Safari 扩展的通信应通过SFSafariExtensionHandler子类执行。

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.建议通过 Xcode 对应的模板创建 Safari Extension,所有重要的设置、Info.plist 字段和基础结构都会为您设置。

Please see good documented details at official Building a Safari App Extension请参阅官方构建 Safari 应用程序扩展中的良好文档详细信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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