Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Action with time intervals in Objective C [closed]

In my iPhone app,from one of the views I want to print NSLog(@"Refreshed"); in all 1 minute interval. How can I do that?

like image 571
Nithin M Keloth Avatar asked Sep 19 '25 15:09

Nithin M Keloth


1 Answers

Use NSTimer like bellow:-

Define NSTimer in your .h class

NSTimer *TimeOfActiveUser;

in .m

- (void)viewWillAppear:(BOOL)animated
{

 TimeOfActiveUser = [NSTimer scheduledTimerWithTimeInterval:60.0  target:self selector:@selector(actionTimer) userInfo:nil repeats:YES];
}


-(void)actionTimer
{

   //Print your log

}

IF YOU WISH TO STOP NSTIMER..? SET ANOTHER ACTION LIKE

-(void)stopTimer
{

    [TimeOfActiveUser invalidate];
    TimeOfActiveUser = nil;

}

Hope its help's you my Friend.. happy coding :)

like image 199
Nitin Gohel Avatar answered Sep 22 '25 10:09

Nitin Gohel