繁体   English   中英

ios:定时器在模拟器中工作但不在设备上工作

[英]ios: Timer working in simulator but not on device

我目前正在Swift应用程序上使用时间。 在以前的应用程序中,我没有遇到任何问题但是对于这个我有一个特定的行为:计时器上的计时器工作正常,但从未在真实设备上启动(10.0.2)。

NSTimer.scheduledTimerWithTimeInterval(5.0, target:self, selector: #selector(AppDelegate.testTimer), userInfo: nil, repeats: true);

这是函数调用

func testTimer(){
  print("Timer called")
}

我没有看到任何错误...我试图在不同的地方创建这个计时器,结果相同....

编辑:我目前在Swift 2.3

编辑这只是Swift 3中的情况

我无法让你的代码在模拟器或设备上工作,但它可以像这样工作

let appDelegate = UIApplication.shared.delegate as! AppDelegate
Timer.scheduledTimer(timeInterval: 1.0, target:appDelegate, selector: #selector(appDelegate.testTimer), userInfo: nil, repeats: true)

暂无
暂无

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

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