Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 5th, 2012  |  syntax: None  |  size: 1.26 KB  |  hits: 11  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. iOS: Simple Local Notification 3 Days Prior
  2. - (IBAction)scheduleNotifButton:(id)sender {
  3.         NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar];
  4. NSDate *currentDate = [self.datePicker date];
  5.  
  6. NSDateComponents *dateComponents = [[NSDateComponents alloc] init];
  7. [dateComponents setDay:-3];
  8.  
  9. NSDate *targetDate = [calendar dateByAddingComponents:dateComponents toDate:currentDate options:0];
  10.  
  11.         UILocalNotification *localNotif = [[UILocalNotification alloc] init];
  12.         if (localNotif == nil)
  13.             return;
  14.         localNotif.fireDate = targetDate;
  15.         localNotif.timeZone = [NSTimeZone defaultTimeZone];
  16.  
  17.         localNotif.alertBody = @"Event is in 3 days!";
  18.         localNotif.alertAction = nil;
  19.  
  20.         localNotif.soundName = UILocalNotificationDefaultSoundName;
  21.         localNotif.applicationIconBadgeNumber = 0;
  22.  
  23.         [[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
  24.  
  25.     }
  26.        
  27. NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar];
  28. NSDate *currentDate = [self.datePicker date];
  29.  
  30. NSDateComponents *dateComponents = [[NSDateComponents alloc] init];
  31. [dateComponents setDay:-3];
  32.  
  33. NSDate *targetDate = [calendar dateByAddingComponents:dateComponents toDate:currentDate options:0];
  34.  
  35. [dateComponents release];
  36.  
  37. ...