I am implementing long running task for location update send to server. I am using NSTimer to call method after every 60 seconds. I read many posts they are using following code .
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
self.timerLocationUpdateToServer = [NSTimer timerWithTimeInterval:interval
target:self
selector:@selector(retryLocationUpdateToServer)
userInfo:nil
repeats:YES];
dispatch_async(dispatch_get_main_queue(), ^{
[[NSRunLoop mainRunLoop] addTimer:self.timerLocationUpdateToServer forMode:NSDefaultRunLoopMode];
});
});
Do we really need to use dispatch_async ? if yes then Why ?
Some one used two identifier one for timer and other for task.
bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
[app endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
}];
bgTask1 = [app beginBackgroundTaskWithExpirationHandler:^{
[app endBackgroundTask:bgTask1];
bgTask1 = UIBackgroundTaskInvalid;
}];
Do we need to initialize two UIBackgroundTaksIndentifier or one will solve the purpose?
Thanks