Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

calling a method after each 60 seconds in iPhone

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?

like image 364
Chatar Veer Suthar Avatar asked Apr 15 '11 08:04

Chatar Veer Suthar


2 Answers

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"); } 
like image 93
Jhaliya - Praveen Sharma Avatar answered Oct 01 '22 02:10

Jhaliya - Praveen Sharma


Once you set NSTimer to scheduleWithTimeInterval it calls it immediately. You can use

  [self performSelector:@selector(doSomething) withObject:nil afterDelay:60.0f]; 
like image 24
Gal Marom Avatar answered Oct 01 '22 03:10

Gal Marom