Problemas de notificaciones de usuario IOS 10.2 en alerta simple e insignia

Antes de escribir esta publicación, realicé muchas investigaciones sobre UserNotification Framework, que sustituyó a UILocalNotification en IOS 10. También seguí este tutorial para aprender todo sobre esta nueva característica:http://useyourloaf.com/blog/local-notifications-with-ios-10/.

Hoy me encuentro con muchos problemas para implementar notificaciones tan triviales y, dado que es una nueva característica reciente, ¡no pude encontrar ninguna solución (especialmente en el objetivo C)! Actualmente tengo 2 notificaciones diferentes, unaAlerta y unoActualización de la insignia.

El problema de alerta

Antes de actualizar mi teléfono de iOS 10.1 a 10.2, hice una alerta en el Appdelegate que se activa de inmediato cada vez que el usuario cierra la aplicación manualmente:

-(void)applicationWillTerminate:(UIApplication *)application {
        NSLog(@"applicationWillTerminate");

        // Notification terminate
        [self registerTerminateNotification];
}

// Notification Background terminate 
-(void) registerTerminateNotification {
    // the center
    UNUserNotificationCenter * notifCenter = [UNUserNotificationCenter currentNotificationCenter];

    // Content
    UNMutableNotificationContent *content = [UNMutableNotificationContent new];
    content.title = @"Stop";
    content.body = @"Application closed";
    content.sound = [UNNotificationSound defaultSound];
    // Trigger 
    UNTimeIntervalNotificationTrigger *trigger = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:1 repeats:NO];
    // Identifier
    NSString *identifier = @"LocalNotificationTerminate";
    // création de la requête
    UNNotificationRequest *terminateRequest = [UNNotificationRequest requestWithIdentifier:identifier content:content trigger:trigger];
    // Ajout de la requête au center
    [notifCenter addNotificationRequest:terminateRequest withCompletionHandler:^(NSError * _Nullable error) {
        if (error != nil) {
            NSLog(@"Error %@: %@",identifier,error);
        }
    }];
}

Antes de iOS 10.2 funcionaba bien, cuando cerré la aplicación manualmente, apareció una alerta. Pero desde que actualicé a IOS 10.2, no aparece nada sin ningún motivo, no he cambiado nada y no puedo ver lo que falta.

El problema de la insignia

También intenté (solo en IOS 10.2 esta vez) implementar un distintivo en el ícono de mi aplicación que funcionó bien, hasta que intenté eliminarlo. Aquí está la función que lo hace:

+(void) incrementBadgeIcon {
    // only increment if application is in background 
    if ([[UIApplication sharedApplication] applicationState] == UIApplicationStateBackground){

        NSLog(@"increment badge");

        // notif center 
        UNUserNotificationCenter *notifCenter = [UNUserNotificationCenter currentNotificationCenter];

        // Content
        UNMutableNotificationContent *content = [UNMutableNotificationContent new];
        content.badge = [NSNumber numberWithInt:1];
        // Trigger 
        UNTimeIntervalNotificationTrigger *trigger = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:1 repeats:NO];
        // Identifier
        NSString *identifier = @"LocalNotificationIncrementBadge";
        // request
        UNNotificationRequest *incrementBadgeRequest = [UNNotificationRequest requestWithIdentifier:identifier content:content trigger:trigger];
        // Ajout de la requête au center
        [notifCenter addNotificationRequest:incrementBadgeRequest withCompletionHandler:^(NSError * _Nullable error) {
            if (error != nil) {
                NSLog(@"Error %@: %@",identifier,error);
            }
        }];
    }
}

Por ahora no incrementa el número de insignia, como su nombre debería sugerir, pero solo establece el número de insignia en 1. La documentación dice que si configuracontent.badge a 0, lo elimina, pero esto no funciona. Intenté con otros números, cuando lo cambio manualmente a '2', '3', etc., cambia, pero si lo configuro a 0, no funciona.

Además, en el tutorial que vinculé anteriormente, se mencionan varias funciones comogetPendingNotificationRequests: completeHandler: ygetDeliveredNotificationRequests: completeHandler:. Me di cuenta de que cuando llamo a estas funciones justo después de llamarincrementBadgeIcon, si content.badge está establecido en '1', '2', etc., aparece en la lista de notificaciones pendientes. Sin embargo, cuando lo configuro en 0, no aparece en ningún lado. No recibo ningún error, no hay advertencia en Xcode, y mi insignia de aplicación aún permanece.

¿Alguien sabe cómo puedo solucionar estas dos alertas?

Gracias de antemano

PD: también intenté usarremoveAllPendingNotificationRequests yremoveAllDeliveredNotifications para ambos sin éxito.

Respuestas a la pregunta(3)

Su respuesta a la pregunta