Notificação por push não recebida quando o aplicativo está em segundo plano no iOS 10
Estou usando o FCM (Firebase Cloud Messaging) para enviar notificações por push no iOS.
Consigo receber a notificação quando o aplicativo estiver no estado de primeiro plano. Mas quando o aplicativo está em estado de segundo plano, a notificação não é recebida. Sempre que o aplicativo chegar ao primeiro plano, somente então a notificação será recebida.
Meu código é:
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
willPresentNotification:(UNNotification *)notification
withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {
// Print message ID.
NSDictionary *userInfo = notification.request.content.userInfo;
NSLog(@"Message ID: %@", userInfo[@"gcm.message_id"]);
// Pring full message.
NSLog(@"%@", userInfo);
if( [UIApplication sharedApplication].applicationState == UIApplicationStateInactive )
{
NSLog( @"INACTIVE" );
completionHandler(UNNotificationPresentationOptionAlert);
}
else if( [UIApplication sharedApplication].applicationState == UIApplicationStateBackground )
{
NSLog( @"BACKGROUND" );
completionHandler( UNNotificationPresentationOptionAlert );
}
else
{
NSLog( @"FOREGROUND" );
completionHandler( UNNotificationPresentationOptionAlert );
}}
- (void)applicationDidEnterBackground:(UIApplication *)application {
}
Quando o aplicativo está no estado de segundo plano:
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
willPresentNotification:(UNNotification *)notification
withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler
- não é chamado de todo.
Habilitei notificações push e também notificações remotas nos modos de segundo plano no App Capabilities. Mas o aplicativo ainda não está recebendo a notificação.
Mencionei algumas perguntas do StackOverflow, mas não consegui resolver o problema. Há algo a acrescentar na versão 10 do iOS ou algum erro no meu código?