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
});
});
-(void)gettingNotification {
NSLog(@"calling method ");
}
Try this code
If you want a repeating timer to be invoked on a
dispatch_queue_t
, usedispatch_source_create
with aDISPATCH_SOURCE_TYPE_TIMER
:That creates a timer that runs once every 20 seconds (3rd parameter to
dispatch_source_set_timer
), with a leeway of a one second (4th parameter todispatch_source_set_timer
).To cancel this timer, use
dispatch_source_cancel
:look for more
How do you trigger a block after a delay, like -performSelector:withObject:afterDelay:?