通过swift

时间:2016-10-22 03:53:04

标签: swift today-extension notificationcenter

当我在主应用程序中将UserDefaults放入数据并在一段时间内调用扩展程序func时,

是否可能?

我在这里找到了另一种方式 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")
}

0 个答案:

没有答案