nstimer

NSTimer Keep counting after app is closed in iPhone

一世执手 提交于 2019-12-01 09:41:39
问题 I have a timer that have to count up to 8 hours (28800 second) after that it should be released im wondering how to keep the timer running at the background and/or when application is closed? this is the NSTimer : stopWatchTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateTimer) userInfo:nil repeats:YES]; and this is my condition : counter++; if (counter >= 28800) { [stopWatchTimer invalidate]; counter =0; timeLabel.text = @"Time Out"; } 回答1: You can't -

The selector of my NSTimer does not run. Why?

大城市里の小女人 提交于 2019-12-01 09:19:21
My code is: -(void) timerRun{...} -(void) createTimer { NSTimer *timer; timer = [NSTimer timerWithTimeInterval:1.0 target:self selector:@selector(timerRun) userInfo:nil repeats:YES]; } viewDidLoad { [NSThread detachNewThreadSelector:@selector(createTimmer) toTarget:self withObject:nil]; ... } When I debug, the method createTimer runs ok, but the method does timerRun not run? Just creating a timer doesn't start it running. You need to both create it and schedule it. You're actually going to have to do slightly more work than that if you want it to run on a background thread. NSTimer s attach to

Problem while Working in background and Nstimer?

ぃ、小莉子 提交于 2019-12-01 09:05:18
问题 Hi i have atask to develop the application with Nstimer and background process. I have already implement background process with timer. And it is excuting good.but i have problem when i minimize application first time at that time it is not running the background process. after minimizing application 3 to 4 times. After that it is working smoothly. i also display the code of background task and timer as follow. - (void)applicationDidEnterBackground:(UIApplication *)application { UIApplication

The selector of my NSTimer does not run. Why?

耗尽温柔 提交于 2019-12-01 06:37:21
问题 My code is: -(void) timerRun{...} -(void) createTimer { NSTimer *timer; timer = [NSTimer timerWithTimeInterval:1.0 target:self selector:@selector(timerRun) userInfo:nil repeats:YES]; } viewDidLoad { [NSThread detachNewThreadSelector:@selector(createTimmer) toTarget:self withObject:nil]; ... } When I debug, the method createTimer runs ok, but the method does timerRun not run? 回答1: Just creating a timer doesn't start it running. You need to both create it and schedule it. You're actually going

(NSTimer) creating a Timer Countdown

吃可爱长大的小学妹 提交于 2019-12-01 05:24:32
I am trying to create a simple Countdown Timer so that when a player enters my game the timer begins from 60 down to 0. It seems simple but I am getting confused at how I write this. So far I have created a method within my GameController.m that looks like this: -(int)countDownTimer:(NSTimer *)timer { [NSTimer scheduledTimerWithTimeInterval:-1 invocation:NULL repeats:YES]; reduceCountdown = -1; int countdown = [[timer userInfo] reduceCountdown]; if (countdown <= 0) { [timer invalidate]; } return time; } At the start of the game I initialise the integer Time at 60. The label is then being set

Adding and Subtracting times in Swift

。_饼干妹妹 提交于 2019-12-01 04:09:54
问题 I've written some of this in pseudo code because I don't know the syntax for it. I'd like to have the timeLeftLabel.text reflect how many hours, minutes, and seconds are left until the 6 hours are up. My biggest problem is that I don't know how to add and subtract times. Can anyone help me? var timer = NSTimer() func timerResults() { let theDate = NSDate() var endTime = theDate //+ 6 hours let timeLeft = endTime //- theDate timeLeftLabel.text = "\(timeLeft)" } @IBOutlet weak var timeLeftLabel

Add a delay to a for loop in swift

荒凉一梦 提交于 2019-12-01 03:30:29
问题 I have a coding 'issue'. I have a label, which text I want to change dynamically every 2 seconds. I've done the following: // WELCOME STRING ARRAY let welcomeContainer:[String] = ["Welcome","Benvenuti","Bienvenue","Willkommen","üdvözlet","Dobrodošli","добро пожаловать","Witajcie","Bienvenido","Ласкаво просимо","Vitajte","欢迎你来"] and then, rather than using a timerwithinterval (which seemed to be too much for this simple task), I tried with the delay method in my function inside for loop: func

(NSTimer) creating a Timer Countdown

橙三吉。 提交于 2019-12-01 02:45:29
问题 I am trying to create a simple Countdown Timer so that when a player enters my game the timer begins from 60 down to 0. It seems simple but I am getting confused at how I write this. So far I have created a method within my GameController.m that looks like this: -(int)countDownTimer:(NSTimer *)timer { [NSTimer scheduledTimerWithTimeInterval:-1 invocation:NULL repeats:YES]; reduceCountdown = -1; int countdown = [[timer userInfo] reduceCountdown]; if (countdown <= 0) { [timer invalidate]; }

NSTimer Category + Blocks implementation to replace selector

江枫思渺然 提交于 2019-12-01 00:05:28
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; @end #import "NSTimer+Additions.h" static VoidBlock _voidBlock; @interface NSTimer (AdditionsPrivate)

Swift 4 Timer Crashes with NSException

老子叫甜甜 提交于 2019-12-01 00:00:42
I've been searching for a way to use a Timer in Swift 4 and looked at this article. I test out my code in xcode and when the the timer first ticks (in this case after 10 seconds) the app crashes and I get an error, although the build succeeded. 2017-11-20 19:54:42.781502-0700 Rock Prodigy[3022:554505] -[_SwiftValue tick]: unrecognized selector sent to instance 0x608000051520 2017-11-20 19:54:42.791278-0700 Rock Prodigy[3022:554505] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[_SwiftValue tick]: unrecognized selector sent to instance 0x608000051520' ***