简体   繁体   English

剂量NSTimer可用于Today Extension(Widget)吗?

[英]Dose NSTimer can be used in Today Extension (Widget)?

I want to use a NSTimer in Today Extension to refresh the widget, but I don't know dose this behaviour is legality? 我想在今日扩展中使用NSTimer来刷新小部件,但我不知道剂量这种行为是否合法?

I was make a demo use a NSTimer to counting and refresh the widget UI every 1 second, seem like it's work, but the problem is when user exit Notification Center, the timer is still running, When and Where should I stop the timer? 我做了一个演示使用NSTimer来计算并每1秒刷新一次窗口小部件UI,看起来像是工作,但问题是当用户退出通知中心时,计时器仍在运行,何时何地应该停止计时器?

I can also confirm that this approach works well for me. 我也可以确认这种方法适合我。

override func viewDidDisappear(animated:Bool) {
    // stop the timer here when notification center is closed
}

Interestingly, both viewWillDisappear and viewDidDisappear are both called together one after another (in that order) as soon as you start to swipe up to close the notification center. 有趣的是,只要您开始向上滑动以关闭通知中心, viewWillDisappearviewDidDisappear都会一个接一个地按照该顺序一起viewDidDisappear This means that while notification center and your widget are still visible on the screen (if you keep your finger on the drag handle) viewDidDisappear is already called. 这意味着虽然通知中心和您的小部件仍然可以在屏幕上看到(如果您将手指放在拖动手柄上),则已调用viewDidDisappear

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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