Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I suspect that what you really want to do is not to compare the dates, but to set the fire date of the notification to the date you got from the array.</p> <p>To do that, you enumerate the array and launch an NSNotification for each timerDate:</p> <pre> <code> NSArray *timerDates = [NSUser Defaults standardUserDefaults] objectforKey:@"time"]; NSDate *now = [NSDate date]; UILocalNotification *localNotif = [[UILocalNotification alloc] init]; // .... general setup of all notifs here. for (NSDate * aDate in timerDates) { localNotif.fireDate = aDate; //... further setup of each individual notif here.... [[UIApplication sharedApplication] scheduleLocalNotification:localNotif]; } [localNotif release]; </code> </pre> <p>However, from your code, it looks like you're getting a single date from defaults:</p> <pre><code>NSDate *newtestdate = [[NSUserDefaults standardUserDefaults]objectForKey:@"time"]; </code></pre> <p>but you save an array there in the method</p> <pre><code>-(void)convertDueDateFormat{ ... [[NSUserDefaults standardUserDefaults] setObject:array_dates forKey:@"time"]; </code></pre> <p>So which one is it? If you have an array, you can test its values as dates:</p> <pre><code>NSArray *timerDates = [NSUser Defaults standardUserDefaults] objectforKey:@"time"]; NSDate *now = [NSDate date]; _block int timerIndex; // can be changed inside the block // use a block to enumerate the array [timerDates enumerateObjectsUsingBlock:^(id obj,NSUInteger index, BOOL *stop){ if(fabs([(NSDate *)obj timeIntervalSinceDate:now])&lt; 1.0) { *stop=YES; timerIndex = index; } } ]; </code></pre> <p>Then use timerIndex to get the right date:</p> <pre><code>localNotif.firedate = [timerDates objectAtIndex:timerIndex]; </code></pre> <p>Definitely also look at the documentation for comparing dates (Apple class documentation for NSDate is good). This is just one way to do it, and probably not the best.<br> (sorry about my formatting. I'm kinda new at this)</p>
 

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