I have use following methods to receive notifications in AppDelegate
. When user is on foreground notification receives as expected. But if user is on background notification will receive(in AppDelegate) notification
only if user tapped a popup. How to receive notification without involving user tap when app running on background.
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
willPresentNotification:(UNNotification *)notification
withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler
{
NSLog( @"Handle push from foreground" );
// custom code to handle push while app is in the foreground
[[ACBRemoteNotificationManger sharedManager] addNotificationFromUNNotification:notification];
}
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
didReceiveNotificationResponse:(UNNotificationResponse *)response
withCompletionHandler:(void (^)())completionHandler
{
NSLog( @"Handle push from background or closed" );
// if you set a member variable in didReceiveRemoteNotification, you will know if this is from closed or background
NSLog(@"%@", response.notification.request.content.userInfo);
}
If this is really your requirement to execute some method/code on receiving PUSH in background mode you have to implement
application:didReceiveRemoteNotification:fetchCompletionHandler:
It is stated in Documentation
Check this Doumentation Link too
Otherwise PUSH notification can not be handled without user interaction