title: iOS: Simple Local Notification 3 Days Prior
body: <p>I wrote an app that allows the user to enter a date on a date picker, and then when they tap a button it will schedule a local notification. The only issue is, the notification fires right when I tap the button. Any help is much appreciated! Here is my code:</p>
  
  <pre><code> - (IBAction)scheduleNotifButton:(id)sender {
          NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar];
  NSDate *currentDate = [self.datePicker date];
  
  NSDateComponents *dateComponents = [[NSDateComponents alloc] init];
  [dateComponents setDay:-3];
  
  NSDate *targetDate = [calendar dateByAddingComponents:dateComponents toDate:currentDate options:0];
  
          UILocalNotification *localNotif = [[UILocalNotification alloc] init];
          if (localNotif == nil)
              return;
          localNotif.fireDate = targetDate;
          localNotif.timeZone = [NSTimeZone defaultTimeZone];
  
          localNotif.alertBody = @"Event is in 3 days!";
          localNotif.alertAction = nil;
  
          localNotif.soundName = UILocalNotificationDefaultSoundName;
          localNotif.applicationIconBadgeNumber = 0;
  
          [[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
  
      }
  </code></pre>