是否可能?
我在这里找到了另一种方式 How to send and receive data in Today extensions
但它不起作用,以下是我的代码
主要应用
@IBOutlet weak var nextButton: UIButton! {
didSet {
nextButton.addTarget(self, action: #selector(selectNextButton), for: UIControlEvents.touchUpInside)
}
}
func selectNextButton() {
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "SpecialKey"), object: nil, userInfo: ["MyData": 10])
}
今天的延期
override func viewDidLoad() {
super.viewDidLoad()
NotificationCenter.default.addObserver(self, selector: #selector(dataReceived(notification:)), name: NSNotification.Name(rawValue: "SpecialKey"), object: nil)
}
func dataReceived(notification: NSNotification) {
print("Received Data")
}