I’d like to use a NSTimer as a background task. I’ve written this code:
UIBackgroundTaskIdentifier bgTask;
UIApplication *app = [UIApplication sharedApplication];
bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
[app endBackgroundTask:bgTask];
}];
self.silenceTimer = [NSTimer scheduledTimerWithTimeInterval:30 target:self selector:@selector(findlocation:) userInfo:nil repeats:NO];
But it doesn’t fire the findlocation method after 30 seconds. Please guide me how to do this.
Try this code: