NSDistributedNotificationCenter 不工作

NSDistributedNotificationCenter not working

我正在实施 VPN 应用程序(数据包隧道提供商)。

我有一个 "containing" 应用程序和一个扩展程序。 这两个应用程序都处于沙盒模式。 我想使用 NSDistributedNotificationCenter 并将消息从扩展程序发送到包含应用程序,但它不起作用。

这是分机的代码:

let distributedNotificationCenter = NSDistributedNotificationCenter.defaultCenter()
distributedNotificationCenter.postNotificationName("myNotification", object: nil, userInfo: nil, deliverImmediately: true)

这是在包含的应用程序中:

let distributedNotificationCenter = NSDistributedNotificationCenter.defaultCenter()
distributedNotificationCenter.addObserver(self, selector: #selector(CNConnectViewController.doNotification(_:)), name: "myNotification", object: nil)

func doNotification(message: NSNotification) {
     NSLog("doNotification")
}

我错过了什么吗?

显然,为了使它起作用,需要使用一个对象名称,因为有沙箱

正在向其他任务发送广播通知中的用户信息字典。使用 App Sandbox,当发布到 NSDistributedNotificationCenter 对象以发送其他任务时,您不能包含用户信息字典。