calling a method after each 60 seconds in iPhone
Swift 3:
Timer.scheduledTimer(withTimeInterval: 60, repeats: true, block: { (timer) in
print("That took a minute")
})
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 scheduleWithTimeInterval it calls it immediately. You can use
[self performSelector:@selector(doSomething) withObject:nil afterDelay:60.0f];
Use the following code:
NSTimer* timer = [NSTimer scheduledTimerWithTimeInterval: 60.0 target: self
selector: @selector(timerFired:) userInfo: nil repeats: YES];
- (void)timerFired:(NSTimer*)theTimer{
if(condition){
[theTimer isValid]; //recall the NSTimer
//implement your methods
}else{
[theTimer invalidate]; //stop the NSTimer
}
}