0

I have a date from date picker in ios, I get the date and the time and I convert this to string and saved in localStorage. Then, I get this string date and convert it to NSDate and use it in my notification. But my problem is that the notification are not run because the date changes after conversion.

The time and date from picker is: dateFromPicker=Thursday-20-March-2014 09:21 AM

The time and date from picker before 4 hours is :StringDateBefore4hours=Thursday-20-March-2014 05:21 AM

The string time before 4 hours after converting to NSDate is :DateBefore4hours=2014-03-20 00:21:00 +0000

The time is changed and my notification not run on the time selected what can we do help me please please .

Ali Abbas
  • 4,247
  • 1
  • 22
  • 40
  • UILocalNotification *notification = [[UILocalNotification alloc] init]; notification.alertBody = @"local app notification on exam day"; [notification setFireDate:dateBfore4hours]; notification.timeZone = [NSTimeZone defaultTimeZone]; notification.applicationIconBadgeNumber = [[UIApplication sharedApplication] applicationIconBadgeNumber] + 1; [[UIApplication sharedApplication] scheduleLocalNotification:notification]; – user3427791 Mar 20 '14 at 07:27
  • Show us how do you do this please: `i get the date and the time and i convert this to string and saved in localStorage, then a get this string date and convert this to NSDate` – Desdenova Mar 20 '14 at 07:51
  • i mean i convert a string date to NSDate form and use this in notification but the time changed when converting – user3427791 Mar 20 '14 at 07:57

1 Answers1

0

That is code for getting date from picker and assigning to notification

NSDate *date=[self.DatePicker date];
UILocalNotification* localNotification = [[UILocalNotification alloc] init];
localNotification.fireDate = date;
localNotification.alertBody = self.TextField.text;
localNotification.timeZone = [NSTimeZone defaultTimeZone];
localNotification.applicationIconBadgeNumber=[[UIApplication       sharedApplication]applicationIconBadgeNumber]+1;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
johny kumar
  • 1,270
  • 2
  • 14
  • 24