nstimer

calling a method after each 60 seconds in iPhone

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-28 05:18:16
I have created an GKSession and as its object is created, it starts search for availability of devices, as - (void)session:(GKSession *)session peer:(NSString *)peerID didChangeState:(GKPeerConnectionState)state { I want to call this method after each 60 seconds, what should I do? Use NSTimer NSTimer* myTimer = [NSTimer scheduledTimerWithTimeInterval: 60.0 target: self selector: @selector(callAfterSixtySecond:) userInfo: nil repeats: YES]; After each 60.0 second , iOS will call the below function -(void) callAfterSixtySecond:(NSTimer*) t { NSLog(@"red"); } Once you set NSTimer to

NSTimer doesn't stop with invalidate

风流意气都作罢 提交于 2019-11-28 04:12:21
问题 I add timer like this tim=[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(repeatTim) userInfo:nil repeats:YES]; [[NSRunLoop mainRunLoop] addTimer:tim forMode:NSDefaultRunLoopMode]; tim it is NSTimer property of my class. Then i stop it on button click like [[fbt tim] invalidate]; [fbt setTim:nil]; fbt it is instance of my class. if i call only invalidate then it doesn't stop, but if i set it to nil then i got EXC_BREAKPOINT here code of repeatTim method in selector

Implementing a Countdown Timer in Objective-c?

你离开我真会死。 提交于 2019-11-28 04:11:44
I am new to iOS programming. I am working on words matching game. In this game I need to implement time counter which shows minutes and seconds. I want when my game is started my timer to start with 3 minutes. Now I want to decrease this timer in reverse direction with seconds. my code just work for seconds..here is my code: secondsLeft--; int seconds = (secondsLeft %3600) % 60; Timerlbl.text = [NSString stringWithFormat:@"%02d",seconds]; if (seconds==0) { UIAlertView *pAlert = [[UIAlertView alloc]initWithTitle:@"Sorry!!" message:@"TimeOver" delegate:self cancelButtonTitle:@"OK"

What is difference between self.timer = nil vs [self.timer invalidate] in iOS?

本小妞迷上赌 提交于 2019-11-28 03:08:25
问题 Can anyone explain me self.timer=nil vs [self.timer invalidate] ? What exactly happens at the memory location of self.timer ? In my code self.timer=nil doesn't stops the timer but [self.timer invalidate] stops the timer. If you require my code I will update that too. 回答1: Once you have no need to run timer, invalidate timer object, after that no need to nullify its reference. This is what Apple documentation says: NSTimer Once scheduled on a run loop, the timer fires at the specified interval

how to pause and resume NSTimer in iphone

China☆狼群 提交于 2019-11-27 23:38:49
hello I am developing small gameApp. I need to pause the timer,when user goes to another view [say settings view]. when user comes back to that view , I need to resume the timer. can anybody solve this issue ... Thanks in Advance... You can't pause a timer. However, when the user goes to the settings view, you can save the fireDate of the timer and also the current date. After this you invalidate the timer and let the user do his/her stuff. Once he/she switches back to the game, you create a new timer object and set the fire date to the old fire date plus the time the user was in the menu

Stopwatch using NSTimer incorrectly includes paused time in display

血红的双手。 提交于 2019-11-27 23:21:14
This is my code for an iPhone stopwatch. It works as expected and stops and resumes when the buttons are clicked. When I hit "Stop", however, the timer won't stop running in the background, and when I hit "Start" to resume it, it will update the time and skip to where it is currently instead of resuming from the stopped time. How can I stop the NSTimer ? What is causing this to occur? @implementation FirstViewController; @synthesize stopWatchLabel; NSDate *startDate; NSTimer *stopWatchTimer; int touchCount; -(void)showActivity { NSDate *currentDate = [NSDate date]; NSTimeInterval timeInterval

Calling A Method At Specific Time Every Day

馋奶兔 提交于 2019-11-27 23:21:04
My app runs constantly in kiosk mode. Once every 24 hours at a specific time I need to sync some data from core data to a web service. I know how to do the sync piece but I don't know how to schedule the app to make the sync call at a specific time each day e.g. at 02:45 am. Is it possible to do something like this when an app is running constantly? Use Local Notifications. Here is a tutorial: http://www.icodeblog.com/2010/07/29/iphone-programming-tutorial-local-notifications/ Hope this helps u to start... This as well: Local Notifications Background Tasks Figured this out thanks to prompts

How can I make a countdown with NSTimer?

大兔子大兔子 提交于 2019-11-27 22:48:38
How can I make a countdown with an NSTimer using Swift? Bigman Question 1: @IBOutlet var countDownLabel: UILabel! var count = 10 override func viewDidLoad() { super.viewDidLoad() var timer = NSTimer.scheduledTimerWithTimeInterval(0.4, target: self, selector: Selector("update"), userInfo: nil, repeats: true) } func update() { if(count > 0) { countDownLabel.text = String(count--) } } Question 2: You can do both. SpriteKit is the SDK you use for scene, motion, etc. Simple View Application is the project template. They should not conflict In Swift 5.1 this will work: var counter = 30 override func

Swift how to use NSTimer background?

孤街醉人 提交于 2019-11-27 21:39:50
class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() var timer = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: Selector("update"), userInfo: nil, repeats: true) } func update() { println("Something cool") } } It's ok for the Simulator ,I will get continuous "Something cool" through I tapped the home button. But it worked out when I debug the app with my iPhone. I did't get anything when I tapped the home button and make my app run background. Someone told me I can play a long blank music to make my App run in the background.But I don't

Xcode 7.3 / Swift 2: “No method declared with Objective-C selector” warning

前提是你 提交于 2019-11-27 19:58:56
I've been using selectors for a while, and even after migrating to Swift I was able to use them without issues. That's how I was using on Swift 2 without issues until I updated Xcode to version 7.3: As use can see I use selectors with NSTimer. This is the action that is called: func Start () { } As you can see Xcode 7.3 now gives a warning "No method declared with Objective-C selector". By clicking on the warning, Xcode offers a quick fix to the code by adding "Selector", but then I still get the same warning: Since Swift 2.2 / Xcode 7.3 there is a new way to use a selector: Selector("funcName