How to know which fireDate of the next scheduled notification?

0

I'd like to know if there's a way to get the next fireDate from the current date.

I have a method that creates the notification and repeats it every time. How do I get the next fireDate ? You would need this to display in a string.

- (void)criarNotificacao {
    NSDate *novaData = self.data;
    for (int i = 0; i < (24/self.intervalo); i++) {
        UILocalNotification *notificacao = [[UILocalNotification alloc] init];
        notificacao.fireDate = novaData;
        notificacao.alertBody = self.nome;
        notificacao.soundName = UILocalNotificationDefaultSoundName;
        notificacao.timeZone = [NSTimeZone defaultTimeZone];
        notificacao.repeatInterval = NSCalendarUnitDay;
        notificacao.applicationIconBadgeNumber = 1;
        [[UIApplication sharedApplication] scheduleLocalNotification:notificacao];
        novaData = [NSDate dateWithTimeInterval:(self.intervalo*3600) sinceDate:novaData];
    }
}
    
asked by anonymous 07.04.2015 / 05:26

1 answer

1

The class UIApplication has the property scheduledLocalNotifications , which has a list with all scheduled notifications.

You can have something like this:

UIApplication *application = [UIApplication sharedApplication];
NSArray *notifications = [application scheduledLocalNotifications];

And on top of this array , get the next notification based on your date, resulting in a UILocalNotification object.

NSSortDescriptor *fireDateDesc = [NSSortDescriptor sortDescriptorWithKey:@"fireDate" ascending:YES];
NSArray *sorted = [notifications sortedArrayUsingDescriptors:@[fireDateDesc]]
UILocalNotification *nextNotification =  [sorted objectAtIndex:0];
    
07.04.2015 / 13:46