1

is possiblity when i put a data by UserDefaults in main app, and call the extension func in a time?

i find an other way in here
How to send and receive data in Today extensions

but it's not working, the following is my code

main app

@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])
}

today extension

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")
}
Community
  • 1
  • 1
Water Magical
  • 979
  • 1
  • 9
  • 13

0 Answers0