nstimer

method not called with dispatch_async and repeating NSTimer

笑着哭i 提交于 2019-11-29 04:27:45
I am developing an app where i want to call method in separate queue using dispatch_async . I want to call that method repeatedly after certain interval of time. But the method is not getting called. I don't know whats wrong. Here is my code: dispatch_async( NotificationQueue, ^{ NSLog(@"inside queue"); timer = [NSTimer scheduledTimerWithTimeInterval: 20.0 target: self selector: @selector(gettingNotification) userInfo: nil repeats: YES]; dispatch_async( dispatch_get_main_queue(), ^{ // Add code here to update the UI/send notifications based on the // results of the background processing }); })

Swift Solid Metronome System

早过忘川 提交于 2019-11-29 03:55:31
问题 I am trying to build a reliable solid system to build a metronome in my app using SWIFT. I Have built what seems to be a solid system using NSTimer so far.. The only issue I am having right now is when the timer starts the first 2 clicks are off time but then it catches into a solid timeframe. Now after all my research I have seen people mention you should use other Audio tools not relying on NSTimer.. Or if you choose use NSTimer then it should be on its own thread. Now I see many confused

What is the best way to make a bouncing ball animation with infinite loop on iPhone?

二次信任 提交于 2019-11-29 02:46:16
I am developing an iPhone game in which birds bounce. I have set up the images for animating the wings of the flying bird like this: [imgBird[i] setAnimationImages:birdArrayConstant]; [imgBird[i] setAnimationDuration:1.0]; [imgBird[i] startAnimating]; Now how I make the bird move is to use an NSTimer to fire every 0.03 seconds which adds/subtracts 1 from the x or y coordinate from imgBird[i].center. I learnt about doing it like this from here. http://icodeblog.com/2008/10/28/iphone-programming-tutorial-animating-a-ball-using-an-nstimer/ But the issue is the birds slow down as soon as another

NSTimer memory management

牧云@^-^@ 提交于 2019-11-29 02:42:02
问题 When I execute this code: [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(showButtons) userInfo:nil repeats:NO]; do I need to nil it or release it, ot whatever for memory management? I am using ARC 回答1: Yes, NSTimer will maintain a strong reference to the target , which can cause (especially in repeating timers) strong reference cycles (a.k.a. retain cycles). In your example, though, the timer does not repeat, and is delayed only 0.5, so worst case scenario, you

Creating a StopWatch in Iphone

拜拜、爱过 提交于 2019-11-29 02:31:53
I am trying to create a simple stopwatch. I referred to this website ( http://www.apptite.be/tutorial_ios_stopwatch.php ) to do this app. When I click the start button, I get -596:-31:-23:-648 and the stopwatch does not run. The code looks like: ViewController.h #import <UIKit/UIKit.h> @interface ViewController : UIViewController{ UILabel *lbl; NSTimer *stopTimer; NSDate *startDate; } @property (strong,nonatomic) IBOutlet UILabel *lbl; -(IBAction)startPressed:(id)sender; -(IBAction)stopPressed:(id)sender; -(void)updateTimer; @end ViewController.m #import "ViewController.h" @interface

NSTimer not working while dragging a UITableView

帅比萌擦擦* 提交于 2019-11-29 01:27:57
I have an application with a countdown timer. I've made it with a label that is updated with a function called from a timer this way: ... int timeCount = 300; // Time in seconds ... NSTimer *myTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(actualizarTiempo:) userInfo:nil repeats:YES]; ... - (void)actualizaTiempo:(NSTimer *)timer { timeCount -= 1; if (timeCount <= 0) { [timer invalidate]; } else { [labelTime setText:[self formatTime:timeCount]]; } } Note: formatTime is a function which receive an integer (number of seconds) and returns a NSString with format mm

NSTimer requiring me to add it to a runloop

跟風遠走 提交于 2019-11-29 00:56:52
问题 I am wondering if someone can explain why dispatching back to the main queue and creating a repeating NSTimer I am having to add it to RUN LOOP for it too fire? Even when using performselectorOnMainThread I still have to add it to a RUN LOOP to get it to fire. Below is an example of my question: #define queue dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0) #define mainqueue dispatch_get_main_queue() - (void)someMethodBeginCalled { dispatch_async(queue, ^{ int x = 0; dispatch

How to pass an argument to a method called in a NSTimer

a 夏天 提交于 2019-11-29 00:15:27
I have a timer calling a method but this method takes one paramether: theTimer = [NSTimer scheduledTimerWithTimeInterval:animationInterval target:self selector:@selector(timer) userInfo:nil repeats:YES]; should be theTimer = [NSTimer scheduledTimerWithTimeInterval:animationInterval target:self selector:@selector(timer:game) userInfo:nil repeats:YES]; now this syntax doesn't seems to be right. I tried with NSInvocation but I got some problems: timerInvocation = [NSInvocation invocationWithMethodSignature: [self methodSignatureForSelector:@selector(timer:game)]]; theTimer = [NSTimer

How keep NSTimer when application entering background?

冷暖自知 提交于 2019-11-28 23:53:08
I'm here because a didn't find any solutions for my issue :( I'm doing an simple application in which i have to send (by socket) some informations to a server (like GPS l/L, accuracy, Battery level, etc). The current code works fine when application is in foreground. myTimer = [NSTimer scheduledTimerWithTimeInterval: 2.0 target:self selector: @selector(sendPosToServer:) userInfo:nil repeats: YES]; myTimer2 = [NSTimer scheduledTimerWithTimeInterval: 3.0 target:self selector: @selector(sendBatteryToServer:) userInfo:nil repeats: YES]; myTimer3 = [NSTimer scheduledTimerWithTimeInterval: 5.0

NSTimer with anonymous function / block?

十年热恋 提交于 2019-11-28 22:01:50
问题 I want to be able to schedule three small events in the future without having to write a function for each. How can I do this using NSTimer ? I understand blocks facilitate anonymous functions but can they be used within NSTimer and if so, how? [NSTimer scheduledTimerWithTimeInterval:gameInterval target:self selector:@selector(/* I simply want to update a label here */) userInfo:nil repeats:NO]; 回答1: You can actually call: NSTimer.scheduledTimerWithTimeInterval(ti: NSTimeInterval, target: