I am developing an iOS app which receives apple's remote push notifications at a particular time interval. The notifications are received successfully when app is active as well as when app is in background. But when app is terminated from app switcher/dock, notifications are not received until the app is started again.
I have tried following code to keep app alive in background. This same code is implemented in applicationWillTerminate:
method, but it did not work.
__block UIBackgroundTaskIdentifier bgTask ;
UIApplication *app = [UIApplication sharedApplication];
bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
[app endBackgroundTask:bgTask];
[app enabledRemoteNotificationTypes];
bgTask = UIBackgroundTaskInvalid;
}];
What is the perfect way of receiving notifications even after app is terminated?