【问题标题】:swift 4 Timer to start at specific time, then do the intervalswift 4 定时器在特定时间开始,然后做间隔
【发布时间】:2018-05-23 17:47:32
【问题描述】:

我想每天在同一时间调用一个方法(在一天结束时,比如 23.59)。 我明白要设置一个重复的方法来调用我这样做:

let date = Date()
let timer = Timer(fireAt: date, interval: 86400, target: self, selector: 
#selector(runCode), userInfo: nil, repeats: true)
RunLoop.main.add(timer, forMode: RunLoopMode.commonModes)

每 86400 秒重复一次,这意味着每天。 但是如何设置日期参数从23.59开始,我想要的具体时间。目前,它只是在代码调用它时熄灭。

非常感谢

【问题讨论】:

  • 创建一个间隔为 1 天的计时器是没有意义的。只有当用户让您的应用在前台运行一整天时,它才会起作用。
  • 如果应用程序关闭或在后台,是否不会调用此方法?
  • 不,用户没有使用您的应用,计时器不会运行。

标签: swift timer


【解决方案1】:

【讨论】:

    猜你喜欢
    • 2011-06-04
    • 2015-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多