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