nstimer

Reset an NSTimer's firing time to be from now instead of the last fire

╄→гoц情女王★ 提交于 2019-11-30 15:09:53
问题 I have a NSTimer that fires with an interval of 3 seconds to decrease a value. When I do an action that increases that value, I want to restart the timer to count 3 seconds from that point. For example, if I increase the value and timer will fires in 1 second, I want to change that and make the timer fire in 3 seconds instead. Can I invalidate the timer and create it again? Or can I do it with setFireDate: , using the current date and adding an interval of 3 seconds? 回答1: Yes, you can

Continue countdown timer when app is running in background/suspended

て烟熏妆下的殇ゞ 提交于 2019-11-30 14:20:40
问题 I have a functional countdown timer. The problem is that I need to continue the countdown when the user puts the app in the background. Or suspends the app? I am not sure what the correct terminology is to describe this action. In other words, the user opens the app and starts the countdown. The user should be able to use other apps but the countdown still operate. Also, the countdown should be able to run forever until it finishes or when the user terminates running the app. Here is the code

Send Local Notifications while App is running in the background Swift 2.0

假如想象 提交于 2019-11-30 14:11:27
I am trying to send the user a 'Push Notification style' Alert when the user minimizes the app (by clicking on the iPhone's Home Button or by locking the phone as well). My app continuously parses an XML file (every 10 seconds) and I want the app to continue running so that it sends the user a Local Notification once some condition has been met in my program, even after the user has minimized the app or locked their phone. I've bounced around from tutorials and everyone seems to 'schedule' a Notification, but this isn't going to work for me because my Notification isn't time-based, rather it's

iphone NStimer start in 2 seconds

你说的曾经没有我的故事 提交于 2019-11-30 14:11:14
问题 I am trying to have a block of code run 2 seconds after I 'start' it. I think the NSTimer can do this but can't figure it out. 回答1: The following will do what you need: NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval: 2 target:self selector:@selector(handleTimer:) userInfo:nil repeats:NO]; Then the delegate function: -(void)handleTimer: (NSTimer *) timer { //code } 回答2: NSTimer can be used, but another option is to use performSelector:withObject:afterDelay: It's basically like a

Reset an NSTimer's firing time to be from now instead of the last fire

无人久伴 提交于 2019-11-30 13:46:43
I have a NSTimer that fires with an interval of 3 seconds to decrease a value. When I do an action that increases that value, I want to restart the timer to count 3 seconds from that point. For example, if I increase the value and timer will fires in 1 second, I want to change that and make the timer fire in 3 seconds instead. Can I invalidate the timer and create it again? Or can I do it with setFireDate: , using the current date and adding an interval of 3 seconds? Yes, you can invalidate it. And create it again. You can also use: - (void) myTimedTask { // other stuff this task needs to do /

how to show countdown on uilabel in iphone?

南笙酒味 提交于 2019-11-30 12:16:31
问题 i have a uilabel and a uislider on a view. i want to set label's time using slider.range of slider is 00:00:00 to 03:00:00. means 3 hours.and intervel on slider is 0.5 minutes.also how to show.i want the timer runs even if application is closed. 回答1: First off, there's no way to keep the timer running after your app is closed. Background apps simply aren't allowed on the iPhone. There are ways to fake it with a timer (save a timestamp when the app exits, and check it against the time when it

Spawning a Spritekit node at a random time

瘦欲@ 提交于 2019-11-30 10:22:57
I'm making a game where I have a node that is spawning and falling from the top of the screen. However I want to make the nodes spawn at random time intervals between a period of 3 seconds. So one spawns in 1 second, the next in 2.4 seconds, the next in 1.7 seconds, and so forth forever. I am struggling with what the code should be for this. Code I currently have for spawning node: let wait = SKAction.waitForDuration(3, withRange: 2) let spawn = SKAction.runBlock { addTears() } let sequence = SKAction.sequence([wait, spawn]) self.runAction(SKAction.repeatActionForever(spawn)) The code for my

Continue countdown timer when app is running in background/suspended

不问归期 提交于 2019-11-30 10:12:00
I have a functional countdown timer. The problem is that I need to continue the countdown when the user puts the app in the background. Or suspends the app? I am not sure what the correct terminology is to describe this action. In other words, the user opens the app and starts the countdown. The user should be able to use other apps but the countdown still operate. Also, the countdown should be able to run forever until it finishes or when the user terminates running the app. Here is the code for my timer: class Timer{ var timer = NSTimer(); // the callback to be invoked everytime the timer

iOS Not the typical background location tracking timer issue

会有一股神秘感。 提交于 2019-11-30 07:54:24
问题 i'm developing a sample app that tracks the user's position in background, but i don't want to leave the location service always enabled, but something in my timer does not behave properly. My idea was that every x minutes, the service goes on, and when it have a correct new location it is released again, now is set to 10 seconds just for testing. (Significant LocationChange did not the trick, not accurated enough) I was searching a lot (iOS Dev center + StackOverflow) and found the "new"

How to know when to invalidate an `NSTimer`

橙三吉。 提交于 2019-11-30 07:35:05
问题 Here's my issue: I have a model class that has an NSTimer in it that I want the Timer to run for the entire lifespan of the model object. Initiliazation is easy: I just have the following line of code in the init method: self.maintainConnectionTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(maintainConnection) userInfo:nil repeats:YES]; However, my issue is, how do I invalidate this timer when the model is released from memory? Now, this would usually be easy,