Note that there are some explanatory texts on larger screens.

plurals
  1. POUILocalNotification show countdown timer on startup or viewdidload
    primarykey
    data
    text
    <p>I'm working on app that sets an UILocalNotification. This is the first time I use it and I'd like to have some explanations to use it efficiently and in the best way. Which is the bast way to countdown to the time of notification expiration? I'd like to show to the user an UILabel with the missing time, this UILabel updates every second and when I reopen my app it must show the timer. I've done this in this way: When I reopen my app or the recall the view that has to show the timer I check if there is a UILocalNotification with the userInfo I've setted previously then I subtract to its NSDate the current time so I get the difference, and update the UILabel. I know it shows time in seconds but if this procedure it's good I will convert it into time.</p> <p>Is there any best way to do this?</p> <p>Here is my code:</p> <p>UILocalNotification *countDownNotificationSetted;</p> <pre><code>NSArray *scheduledNotificationArray = [[UIApplication sharedApplication] scheduledLocalNotifications]; for (int i = 0; i&lt;[scheduledNotificationArray count]; i++) if ([[[[scheduledNotificationArray objectAtIndex:i] userInfo] objectForKey:@"ID"] isEqualToString:@"ParkNotification"]) { countDownNotificationSetted = [scheduledNotificationArray objectAtIndex:i]; break; } NSDate *expringDate = [countDownNotificationSetted fireDate]; NSTimeInterval timeLeftToNotification = [expringDate timeIntervalSinceNow]; if(timeLeftToNotification == 0){ [countDownTimer invalidate]; } datePicker.countDownDuration = timeLeftToNotification; _countDownLabel.text = [NSString stringWithFormat:@"%.0f", timeLeftToNotification]; NSLog(@"%.0f", timeLeftToNotification); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload