简体   繁体   English

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

[英]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.

相关问题 Tabbarcontroller在模拟器上工作而不在iOS设备上 - Tabbarcontroller is working in simulator not on iOS device UIImagePickerController在iOS设备上工作但在iOS模拟器上没有? - UIImagePickerController working on iOS device but not on iOS simulator? free()使用iOS Simulator,但不能在实际设备上使用 - free() working with iOS Simulator but not on real device 本地通知可在ios模拟器上运行,但不能在设备上运行 - Local notifications working on ios simulator but not on device iOS 应用程序链接在设备上不起作用,但在模拟器上打开应用程序 - iOS applink not working on the device but opens app on simulator iOS Webkit不在设备上工作,但在swift的模拟器上运行 - iOS Webkit not working on device, but works on simulator at swift 背景音频在iOS模拟器上可运行,但不能在设备上运行 - background audio working on iOS simulator but not device 音频和振动在模拟器中工作,而不是在ios设备上 - Audio and vibrate working in simulator not on ios device 自动旋转仅在设备上的模拟器中有效(IOS 7.1) - Autorotation only working in simulator not on device (IOS 7.1) 外部JavaScript在模拟器中工作,但不在ios设备中工作 - External javascript working in simulator but not in ios device
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM