我正在实现VPN应用(分组隧道提供程序)。
我有一个“包含”应用和扩展程序。两个应用都处于沙盒模式。我想使用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对象以传递其他任务的消息时,不能包含用户信息字典。