问题
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?
回答1:
If you actively stop the app in the app switcher it stops receiving any push notifications.
This is an intended behaviour as stated by Apple engineers in the developer forums.
来源:https://stackoverflow.com/questions/25176066/get-apples-remote-push-notifications-even-after-app-terminates