Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to check each and every object of array in the userdefaults
    text
    copied!<p>i am saving selected date from picker in array in userdefaults. So when i select a particular date and click on save that particular date is getting saved in userdefaults.This is done properly.But now i have problem.I need to compare each and every date and time of userdefaults with the current time .If an object gets equivalent to the current date and time then the notification should be shown.How is this possible.Thanks. This is my code Here i am selecting my date through date picker and saving date in userdefaults.</p> <pre><code>this is my timepickercontroller.m - (void)viewDidLoad { time = [[NSString alloc] init]; CGRect pickerFrame = CGRectMake(0,40,0,0); datePicker = [[UIDatePicker alloc] initWithFrame:pickerFrame]; datePicker.datePickerMode = UIDatePickerModeTime; datePicker.date = [NSDate date]; [datePicker addTarget:self action:@selector(convertDueDateFormat) forControlEvents:UIControlEventValueChanged]; [self.view addSubview:datePicker]; [datePicker release]; } -(void)convertDueDateFormat{ app = (StopSnoozeAppDelegate*)[[UIApplication sharedApplication]delegate]; app.timerdate = [self.datePicker date]; NSLog(@"picker date:%@",selecteddate); if ([[NSUserDefaults standardUserDefaults] valueForKey:@"time"]==nil) { [[NSUserDefaults standardUserDefaults] setObject:[NSDate date] forKey:@"time"]; [[NSUserDefaults standardUserDefaults] synchronize]; NSLog(@"%@",[[NSUserDefaults standardUserDefaults] objectForKey:@"time"]); } else { NSArray *array = [[NSUserDefaults standardUserDefaults] objectForKey:@"time"]; NSMutableArray *array_dates = [[NSMutableArray alloc] init]; for(int i =0;i&lt;[array count];i++) { [array_dates addObject:[array objectAtIndex:i]]; } [array_dates addObject:app.timerdate]; [[NSUserDefaults standardUserDefaults] setObject:array_dates forKey:@"time"]; [[NSUserDefaults standardUserDefaults] synchronize]; NSLog(@"%@",[[NSUserDefaults standardUserDefaults] objectForKey:@"time"]); } } this is the controller where i am setting notification -(IBAction)save{ dateFormatter = [[NSDateFormatter alloc]init]; [dateFormatter setDateFormat:@"hh:mm a"]; NSDate *currentime = [NSDate date]; currentcheck = [NSString stringWithFormat:@"%@",[dateFormatter stringFromDate:currentime] ]; NSLog(@"currenttime:%@",currentcheck); timepicker = [[TTimePickerController alloc]init]; if (app.timerdate == NULL &amp;&amp; interval == NULL &amp;&amp; newsound == NULL) { UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"UIAlertView" message:@"Set Date,interval,sound for alarm" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alert show]; [alert release]; alert = nil; } else { [self scheduleNotification]; [self saveInDatabase]; } } -(void)scheduleNotification { [[UIApplication sharedApplication]cancelAllLocalNotifications]; timepicker = [[TTimePickerController alloc]init]; NSDate *newtestdate = [[NSUserDefaults standardUserDefaults]objectForKey:@"time"]; NSLog(@"fireDate=%@", newtestdate); NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar]; NSDateComponents *dateComponents = [calendar components:NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit fromDate:newtestdate]; NSDateComponents *timeComponents = [calendar components:NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit fromDate:newtestdate]; NSDateComponents *dateComps = [[NSDateComponents alloc]init]; [dateComps setDay:[dateComponents day]]; [dateComps setMonth:[dateComponents month]]; [dateComps setYear:[dateComponents year]]; [dateComps setHour:[timeComponents hour]]; [dateComps setMinute:[timeComponents minute]]; [dateComps setSecond:[timeComponents second]]; itemDate = [calendar dateFromComponents:dateComps]; [dateComps release]; Class cls = NSClassFromString(@"UILocalNotification"); if (cls!= nil) { UILocalNotification *notif = [[cls alloc]init]; notif.fireDate = itemDate; [app.dateFormatter setDateFormat:@"hh:mm a"]; newstring = [app.dateFormatter stringFromDate:notif.fireDate]; NSLog(@"new fire date:%@",newstring); notif.timeZone = [NSTimeZone defaultTimeZone]; notif.alertBody = @"Alarm"; notif.alertAction = @"View"; notif.soundName = UILocalNotificationDefaultSoundName; notif.applicationIconBadgeNumber=1; notif.repeatInterval = 0; [[UIApplication sharedApplication]scheduleLocalNotification:notif]; [notif release]; } } </code></pre>
 

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