nstimer

How to Fix Error with a Swift NSTimer Calling Its Selector

给你一囗甜甜゛ 提交于 2019-11-30 21:40:30
I'm getting a runtime error of: 2014-07-15 16:49:44.893 TransporterGUI[1527:303] -[_TtC14TransporterGUI11AppDelegate printCountdown]: unrecognized selector sent to instance 0x10040e8a0 when I use the following Swift code to fire a timer: @IBAction func schedule(sender : AnyObject) { var startTime = startDatePicker.dateValue.timeIntervalSinceDate(NSDate()) var endTime = endDatePicker.dateValue.timeIntervalSinceDate(startDatePicker.dateValue) var startDate = NSDate.date() let params = ["startTime": startTime, "startDate": startDate] var counter = NSTimer.scheduledTimerWithTimeInterval(1.0,

Would NSTImer events block the main thread?

匆匆过客 提交于 2019-11-30 21:39:35
When we use a NSTimer, once the call back is called after the mentioned interval, does the UI would be blocked? visakh7 From the documents Timers work in conjunction with run loops. To use a timer effectively, you should be aware of how run loops operate—see NSRunLoop and Threading Programming Guide. Once scheduled on a run loop, the timer fires at the specified interval until it is invalidated. A non-repeating timer invalidates itself immediately after it fires. However, for a repeating timer, you must invalidate the timer object yourself by calling its invalidate method. Calling this method

Iphone app is delayed for 10 -15 minutes when iphone is in sleep mode

荒凉一梦 提交于 2019-11-30 21:18:43
问题 I have created an app that uses NSTimer, which gets triggered each second. My problem is that if the Iphone is in sleep mode i get a delay for 10 to 15 minutes before the event is triggered. I have stackoverflowed and googled this and the reason for this seems to be that the phone stops listening for certain events when in sleep mode. Some people have solved this issue by playing a mute sound, not allowing the phone to sleep. What could be the reason for the delay? The mute sound solution

Unrecognized selector sent to instance NSTimer Swift

人走茶凉 提交于 2019-11-30 20:42:36
I'm trying to developing an app that includes a simple Stopwatch feature. I'm using Xcode 6 and the Swift language. Here is the code in FirstViewController @IBAction func Stopwatch (Sender:UIButton) { var startTime = NSTimeInterval() func updateTime(timer:NSTimer) { //Find Current TIme var currentTime = NSDate.timeIntervalSinceReferenceDate() //Find the difference between current time and start time var elapsedTime :NSTimeInterval = currentTime - startTime //calculate the minutes in elapsed time. let minutes = UInt(elapsedTime / 60.0) elapsedTime -= (NSTimeInterval(minutes) * 60) //calculate

Pausing timer when app is in background state Swift

廉价感情. 提交于 2019-11-30 19:51:48
My ViewController.swift func startTimer() { timer = NSTimer().scheduleTimerWithTimerInvterval(1.0,target: self,selctor: Selector("couting"),userinfo: nil, repeats: true) } func pauseTimer() { timer.invalidate() println("pausing timer") } and this is appDelegate.swift func applicateWillResignActive(application: UIApplication) { viewController().pauseTimer() println("closing app") } It is printing pausing timer and closing app but when I open again I see it never paused. How do I do it correctly? You have to set an observer listening to when the application did enter background. Add the below

NSTimer crashes, when I call [Timer isValid] or [Timer invalidate]

♀尐吖头ヾ 提交于 2019-11-30 18:39:12
I have two NSTimers in my iPhone app. DecreaseTimer works fine, but TimerCountSeconds crashes when I call [timerCountSeconds isValid] or [timerCountSeconds invalidate]. They are used like this: -(id)initialize { //Gets called, when the app launches and when a UIButton is pressed if ([timerCountSeconds isValid]) { [timerCountSeconds invalidate]; } } - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { //Gets called, when you begin touching the screen //.... if ([decreaseTimer isValid]) { [decreaseTimer invalidate]; } timerCountSeconds = [NSTimer scheduledTimerWithTimeInterval:0.1

NSTimer Category + Blocks implementation to replace selector

泄露秘密 提交于 2019-11-30 18:07:46
问题 I am quite new to blocks and objective-c, and i am trying to write my first category using both. My idea is to create a category on NSTimer that will receive a block as a parameter and this block will be used in the selector call. Right now I have this. // NSTimer+Additions.h #import <Foundation/Foundation.h> typedef void (^VoidBlock)(); @interface NSTimer (NSTimer_Additions) + (NSTimer *)scheduleTimerWithTimeInterval:(NSTimeInterval)theSeconds repeats:(BOOL)repeats actions:(VoidBlock)actions

Would NSTImer events block the main thread?

独自空忆成欢 提交于 2019-11-30 17:06:42
问题 When we use a NSTimer, once the call back is called after the mentioned interval, does the UI would be blocked? 回答1: From the documents Timers work in conjunction with run loops. To use a timer effectively, you should be aware of how run loops operate—see NSRunLoop and Threading Programming Guide. Once scheduled on a run loop, the timer fires at the specified interval until it is invalidated. A non-repeating timer invalidates itself immediately after it fires. However, for a repeating timer,

NSTimer Not Stopping When Invalidated

拈花ヽ惹草 提交于 2019-11-30 16:55:51
问题 I have the following code in my .h file: #import <UIKit/UIKit.h> #import <CoreLocation/CoreLocation.h> #import <AVFoundation/AVFoundation.h> #import <MapKit/MapKit.h> @interface LandingController : UIViewController<CLLocationManagerDelegate> { CLLocationManager *LocationManager; AVAudioPlayer *audioPlayer; } @property (nonatomic, retain) NSTimer *messageTimer; - (IBAction)LoginButton:(id)sender; @end I have the following code in my .m file: @interface LandingController () @end @implementation

NSTimer stops during scrolling

守給你的承諾、 提交于 2019-11-30 15:58:51
During debugging my IOS project developed in XCode4 , I initialize and run an NSTimer object. However, the timer stops as soon as I press the scroll view and it continues to run after I release the scroll. Is there a configuration for NSTimer such that timer is not blocked during scrolling? Thanks in advance. Add this single line and try again please [[NSRunLoop mainRunLoop] addTimer:timer forMode:NSRunLoopCommonModes]; 来源: https://stackoverflow.com/questions/17423900/nstimer-stops-during-scrolling