Grand Central Dispatch will create another thread to run. therefore, if the timer method (shown below and suggested above) is behind your application, you will need to put the command in a separate thread.
NSTimer is what you should use. for example, if you want to repeat the method that is initiated by the click of a button, you can do this
- (void)viewDidLoad { [super viewDidLoad]; [cameraControlButtonUp addTarget:self action:@selector(cameraControlButtonUpPressed) forControlEvents:UIControlEventTouchUpInside]; } -(IBAction)buttonDown:(id)sender{ NSInteger tag = [sender tag]; if (tag==1) { buttonCounter=1; timer = [[NSTimer scheduledTimerWithTimeInterval:.5 target:self selector:@selector(sendJoin) userInfo:nil repeats:YES]retain]; } } -(void)sendJoin { switch (buttonCounter) { case 1: [cClient userDigitalPushAndRelease:372]; break; default: break; } } -(void)cameraControlButtonUpPressed { [timer invalidate]; }
which will repeat the command until the button is released. keep in mind that you need to associate ibaction with a button event (only a button click event). as well as create a timer in .h and mark button 1 with which you want to use.
for a simpler example; it's pretty simple. just create your method for calling, timer and set the repeat value to YES. then call invalidate to stop it. I had to create a separate sendJoin method because I could not get the numbers in order to pass this method correctly. but if you donβt have any parameters, itβs even easier. just use the timer syntax to create it, then invalidate it when ur did
source share