I\'m using FCM(Firebase Cloud Messaging) for sending push notifications in iOS.
I\'m able to receive the notification when App is in foreground state. But when the A
For iOS 10, we need to call the 2 methods below.
For FOREGROUND state
- (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
NSLog(@"%@", notification.request.content.userInfo);
completionHandler(UNNotificationPresentationOptionAlert);
}
For BACKGROUND state
- (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);
completionHandler();
}
Before that, we must add the UserNotifications
framework and import in the AppDelegate.h
file
#import <UserNotifications/UserNotifications.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate,UNUserNotificationCenterDelegate>
We've run many tests with our customers and did lots of research on the topic. iOS 10.x, especially 10.3.x has issues handling and displaying pushes. The only way to circumvent the issues is by upgrading to a newer iOS-version.