UILocalNotification does not add me correctly applicationIconBadgeNumber in day change

1

I do not quite understand how the increase in the Badge of the ios works.

With the code that I put next I get the correct notification, but when I spend a day instead of putting, for example from 0 to 1, it happens to 2 ...

I do not understand what he left me or how he increases this value.

Can you help me out?



UILocalNotification* localNotification = [[UILocalNotification alloc] init];

localNotification.fireDate = startDate; // Por ejemplo: Ponemos el día siguiente a las 09:00 de la mañana
localNotification.soundName = UILocalNotificationDefaultSoundName;
localNotification.alertBody =  @"Tiene tareas pendientes para realizar";
localNotification.alertAction = descripcionTextField.text;
localNotification.timeZone = [NSTimeZone defaultTimeZone];
localNotification.applicationIconBadgeNumber = [[UIApplication sharedApplication] applicationIconBadgeNumber] + 1;

NSDictionary *inventory = @{
             @"AcID" : [NSNumber numberWithInt: acuarioSeleccionadoID],
             @"TareaID" : [NSNumber numberWithInt: tareaSeleccionada],
             };

localNotification.userInfo= inventory;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];

    
asked by Shadros 29.02.2016 в 16:41
source

2 answers

0

This counter must be controlled by you, that is, either locally or server-side. iOS will not "auto-increment" the counter if new notifications arrive. Therefore, you have two ways of doing it:

  • When you receive the notification in local, you take the current counter and increase it by 1
  • You manage it from the server (this is the most correct one)
  • answered by 29.02.2016 / 18:04
    source
    0

    By the tests that I have been doing, I come to the following conclusion:

    When we put in creating a UILocalNotification:

    <code>
    localNotification.applicationIconBadgeNumber = [[UIApplication sharedApplication] applicationIconBadgeNumber] + 1;
    </code>
    

    We are saying that, with the bagde number we have at this moment we will add one.

    This means that, if in a few hours we send 2 notifications to the user, the first will put the badge to one, but the second one also, since at the beginning, when the badge was created it was at zero. When we hope he had put 2.

    As has put mhergon, if we want to control the badge we will have to manage it from a server.

    I hope it will help you.

        
    answered by 29.02.2016 в 21:12