gpt4 book ai didi

ios - 如何每 x 秒快速更新今天的小部件

转载 作者:搜寻专家 更新时间:2023-10-30 23:10:29 25 4
gpt4 key购买 nike

我尝试每 x 秒更新一次今天的小部件扩展的内容,因为我试图实现类似 diashow 的东西。因此,我使用共享默认值存储了所有必需的数据。从存储中加载数据工作完美,但扩展的 completionHandler:

    func widgetPerformUpdateWithCompletionHandler(completionHandler: ((NCUpdateResult) -> Void)!) {
//I do load the content here
completionHandler(NCUpdateResult.NewData)
}

只调用一次。我如何实现一个函数,表示“newData”每 x 秒可用一次?

最佳答案

一种方法是 NSTimer。它对于每 x 秒调用一次方法很有用。

var timer : NSTimer?

override func viewDidLoad() {
super.viewDidLoad()

timer = NSTimer.scheduledTimerWithTimeInterval(3, target: self, selector: "animateFrame:", userInfo: nil, repeats: true)
}

func animateFrame(timer: NSTimer) {
// Do something
}

在这种情况下,您可以每 3 秒调用一次 animateFrame:。

关于ios - 如何每 x 秒快速更新今天的小部件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32296509/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com