title: Fire Date issue in local notification
body: <p>I have a view controller which contains a field for user to enter date value.In contrast I have a field called "Remind Before Days" for the user to select when the notification should fire.If the remind before day is same day,then notification is set to fire on the date,but when the remind day is before 1 day,then notification should fire before one day the date set(specified).For this I have written a method called -(void)setNotification and here is the implementation code:</p>
  
  <pre><code>- (void)setNotification
  {
      //Set notification after confirmation of saved data
  
      Class cls = NSClassFromString(@"UILocalNotification");
      UILocalNotification *notif = [[cls alloc] init];
  
      if (cls != nil) 
      {
          textField = [self.fields objectAtIndex:3];
  
          if (textField.text == @"Same Day") 
          {
              notif.fireDate = [datePicker date];
              notif.timeZone = [NSTimeZone defaultTimeZone];
          }
          else if(textField.text == @"1 Day")
          {
              NSDate *now = [datePicker date];
  
              // set up date components
              NSDateComponents *components = [[NSCalendar currentCalendar] components:NSDayCalendarUnit | NSMonthCalendarUnit | NSYearCalendarUnit fromDate:now];
              [components setDay:-1];
  
              // create a calendar to form date
              NSCalendar *gregorian = [[[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar] autorelease];
              NSDate *newDate2 = [gregorian dateByAddingComponents:components toDate:now options:0];
  
              notif.fireDate = newDate2;
              notif.timeZone = [NSTimeZone defaultTimeZone];
          }
          notif.timeZone = [NSTimeZone defaultTimeZone];
          notif.alertBody = textView.text;
          notif.alertAction = @"View";
          notif.soundName = @"lazy_afternoon.mp3";
          notif.applicationIconBadgeNumber = 1;
          textField = [self.fields objectAtIndex:1];
          NSDictionary *userDict = [NSDictionary dictionaryWithObject:self.textField.text forKey:kReminder];
          notif.userInfo = userDict;
          [[UIApplication sharedApplication] scheduleLocalNotification:notif];
          [notif release];
      }
  }
  </code></pre>
  
  <p>Now as we are all aware that when the notification gets fired,the user clicks view.Then we show an alert,the implementation code is written in appDelegate.Here it is:</p>
  
  <pre><code>- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
  {    
  
      // For The Purpose Of Notification.
      Class cls = NSClassFromString(@"UILocalNotification");
      if (cls) 
      {
          UILocalNotification *notification = [launchOptions objectForKey:
                                               UIApplicationLaunchOptionsLocalNotificationKey];
  
          if (notification) 
          {
          NSString *reminderText = [notification.userInfo objectForKey:kReminder];
          [self.viewController showReminder:reminderText];
          }
      }
  
      application.applicationIconBadgeNumber = 0;
  }
  </code></pre>
  
  <p>Now after local notification is received,we do the following i.e.:</p>
  
  <pre><code>- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification 
  {
      application.applicationIconBadgeNumber = 0;
      NSString *reminderText = [notification.userInfo objectForKey:kReminder];
      [self.viewController showReminder:reminderText];
  }
  </code></pre>
  
  <p>Now I have set the -(void)setNotification action to right navigation right bar button item titled "Save" as follows:</p>
  
  <pre><code>-(IBAction)save:(id)sender
  {
  [self setNotification];
  }
  </code></pre>
  
  <p>When I don't specify any condition for fire date i.e. simply assign as :</p>
  
  <p>notif.fireDate = [datePicker date]; everything's fine with notification(no issues).</p>
  
  <p>But when I do as the above i.e. condition for fire date,then the notification is not getting fired.Instead the alert is getting fired when I click save.Also when I quit the simulator,I could see some thread problem.I don't understand what's wrong with the code (implementation).I have gone through several links,also the apple <a href="http://developer.apple.com/library/IOs/#documentation/iPhone/Reference/UILocalNotification_Class/Reference/Reference.html" rel="nofollow">documentation</a> of UILocalNotification.Couldn't find out any property or method to set fire Date according to conditions.</p>
  
  <p>I found out a method "repeatTimeInterval" which is relavant and applicable when a notification must be repeated weekly,yearly etc..which doesn't suit the requirement that the <strong>"date to be fired is this when the remind days in textField is this"</strong> </p>
  
  <p>Can any one please guide me right,</p>
  
  <p>Thanks all in advance :)</p>