[英]ios: Timer working in simulator but not on device
I am currently using a time on a Swift application. 我目前正在Swift应用程序上使用时间。 In previous app I had no problems but for this one I had a particular behavior: the timer works fine on the simulator but is never fired on the real device (10.0.2). 在以前的应用程序中,我没有遇到任何问题但是对于这个我有一个特定的行为:计时器上的计时器工作正常,但从未在真实设备上启动(10.0.2)。
NSTimer.scheduledTimerWithTimeInterval(5.0, target:self, selector: #selector(AppDelegate.testTimer), userInfo: nil, repeats: true);
Here is the function called 这是函数调用
func testTimer(){
print("Timer called")
}
I don't see anything wrong with this... I've tried to create this timer at various place with the same results.... 我没有看到任何错误...我试图在不同的地方创建这个计时器,结果相同....
EDIT: I am currently in Swift 2.3 编辑:我目前在Swift 2.3
EDIT this is only the case in Swift 3 编辑这只是Swift 3中的情况
I couldn't get your code to work on the simulator or the device, but it works on both like this 我无法让你的代码在模拟器或设备上工作,但它可以像这样工作
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.