nstimer

Timer inside global queue is not calling in iOS

守給你的承諾、 提交于 2019-12-04 08:41:23
-(void)viewDidLoad{ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ [NSTimer scheduledTimerWithTimeInterval:0.10 target:self selector:@selector(action_Timer) userInfo:nil repeats:YES]; } ); } -(void)action_Timer{ LOG("Timer called"); } action_Timer is not being called. I dont know why. Do you have any idea? You're calling +[NSTimer scheduledTimerWithTimeInterval:...] from a GCD worker thread. GCD worker threads don't run a run loop. That's why your first try didn't work. When you tried [[NSRunLoop mainRunLoop] addTimer:myTimer forMode:NSDefaultRunLoopMode] ,

iOS 5 deep sleep prevention

自古美人都是妖i 提交于 2019-12-04 08:37:11
I'm trying to build an alarm app that can fire an alarm while in locked-screen mode (the app is in the foreground, but the screen is locked). The alarm has to be triggered by a NSTimer not by uilocalnotification. In iOS 4 I used the 'play silent sound every 10 seconds' hack to prevent the app from going to deep sleep and the timer events worked fine. However, in iOS 5 this doesn't seem to work. Any ideas? Or this should work and I'm doing something wrong? It seems that you actually can use the 'play silent audio' hack in iOS 5, but the audio has to be audible meaning you can't play it at

How do I create an accurate timer event in Objective-C/iOS?

梦想的初衷 提交于 2019-12-04 07:40:55
I'm looking to create a countdown timer for SMPTE Timecode (HH:MM:SS:FF) on iOS. Basically, it's just a countdown timer with a resolution of 33.33333ms. I'm not so sure NSTimer is accurate enough to be counted on to fire events to create this timer. I would like to fire an event or call a piece of code every time this timer increments/decrements. I'm new to Objective-C so I'm looking for wisdom from the community. Someone has suggested the CADisplayLink class, looking for some expert advice. Try CADisplayLink. It fires at the refresh rate (60 fps). CADisplayLink *displayLink = [CADisplayLink

NSTimer Decrease the time by seconds/milliseconds

牧云@^-^@ 提交于 2019-12-04 06:34:27
I am developing a QuiZ app. It needs a countdown timer, In that I want to start a timer at 75:00.00 (mm:ss.SS) and decrease it to 00:00.00 (mm:ss.SS) by reducing 1 millisecond. I want to display an alert that Time UP! when time reaches to 00:00.00 (mm:ss.SS). I am displaying the time by following below link Stopwatch using NSTimer incorrectly includes paused time in display Here is a simple solutions to your problem. Declarations @interface ViewController : UIViewController { IBOutlet UILabel * result; NSTimer * timer; int currentTime; } - (void)populateLabelwithTime:(int)milliseconds; -

NSTimer callback on background thread

萝らか妹 提交于 2019-12-04 06:23:51
问题 I have a NSTimer defined as follows: timer = [NSTimer scheduledTimerWithTimeInterval:30 target:self selector:@selector(fooBar) userInfo:nil repeats:YES]; [[NSRunLoop mainRunLoop] addTimer:timer forMode:NSRunLoopCommonModes]; I want it to call the call back function fooBar in this case using a background thread. But when I check with if ([NSThread mainThread]) i'm always getting it on the main thread. Is there any other way aside from dispatching a thread from the callback function? 回答1: You

NSTimer scheduledTimerWithTimeInterval:target:selector:userInfo:repeats doesn't invoke the method

≡放荡痞女 提交于 2019-12-04 05:49:21
The timer never invokes the method. What am I doing wrong ? This is the code: NSTimer *manualOverlayTimer = [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(hideManual) userInfo:nil repeats:NO]; method: -(void)hideManual thanks aneuryzm It was a thread issue. I've fixed with: dispatch_async(dispatch_get_main_queue(), ^{ // Timer here }); You don't need an NSTimer for a task of this sort. To hide your view object after a specific period of time on main thread you can use a gcd method dispatch_after dispatch_after(dispatch_time(DISPATCH_TIME_NOW, NSEC_PER_SEC * 2.0),

Timer that updates label running in background

我与影子孤独终老i 提交于 2019-12-04 04:56:14
问题 I have coded a timer using an NSTimer that updates a label. The problem is that in the same viewcontroller I have a uitableview and when I scroll it down, the timer doesn't update its value so the user can "cheat" to stop the timer. I think this could be easy to fix with a serial queue with CGD but I don't figure out how to do it. Thanks in advance, Juan 回答1: First of all keep in mind that you cannot perform UI changes in any other thread than the main thread. Having said that, you need the

Stop and Reset NSTimer

谁说胖子不能爱 提交于 2019-12-04 03:48:20
问题 I have a simple timer using that is activated with a button is pushed. It runs from 60 to 0 no problem but what I want is to stop and reset the timer on push button. I have managed to stop it when the button is pressed using the code below but for some reason cannot get it to reset and stop at 60. This should be simple but it isn't working. Any suggestions? Timer is set using simple Action - (IBAction)timerStart:(id)sender { if(!secondCounter == 0){ [countdownTimer invalidate]; } else { [self

What is an NSTimer's behavior when the app is backgrounded?

淺唱寂寞╮ 提交于 2019-12-04 03:30:10
问题 I know that when you background an app, the timer stops running. However, what is the behavior when you come back from the background? Does the timer maintain its original fireDate ? I've run into a bit of an issue where upon returning from the background with an NSTimer set to fire in ten minutes, sometimes I'll immediately have the timer fire before applicationWillEnterForeground: is even called. When it doesn't fire, and applicationWillEnterForeground: is called, I have some logic to check

scheduledTimerWithTimeInterval vs performselector with delay with iOS 5.0

筅森魡賤 提交于 2019-12-04 03:14:29
i am doing function call with scheduledTimerWithTimeInterval. i am just checking that xml parsing is completed or not for particular web services and invalidating timer in didEndElement method after getting successful response. timerForStopWebService = [NSTimer scheduledTimerWithTimeInterval:30.0 target:self selector:@selector(stopWS) userInfo:nil repeats:NO]; now i am facing problem with iOS 5.0 and its working fine in other iOS versions. in iOS 5.0, a function stopWS call anytime even if i am invalidating it. let me know if you have solution for that. and now i am implementing