简体   繁体   中英

ViewDidAppear in Today Extension iOS

class TodayViewController: UIViewController, NCWidgetProviding {

  var label = UILabel()
  var count = 0

override func viewWillAppear(_ animated: Bool) {
    debugPrint("viewWillAppear \(count)")
  }

In my app, it will keep on increase the count when the user press a button on the extension. Then when the user swap the notification centre away, and then reload it, the function viewWillAppear will trigger. And I found that the count is reset to 0 every time when viewWillAppear is triggered. Why?

You view controller might not be cached if the today view is closed. You need to save the value to disk, eg using NSUserDefaults

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM