Advertisement
Guest User

CancelLocalNotifications V2

a guest
Sep 18th, 2012
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
  2. {
  3. [self scheduleCheckTimer];
  4. }
  5. -(void) scheduleCheckTimer
  6. {
  7. [self.timer invalidate];
  8.  
  9. self.timer = [NSTimer scheduledTimerWithTimeInterval: [self.checkDate timeIntervalSinceNow] target: self selector: @selector(checkTimerTimeout) userInfo: nil repeats: NO];
  10. }
  11.  
  12. -(void) checkTimerTimeout
  13. {
  14. [[UIApplication sharedApplication] cancelAllLocalNotifications];
  15. [self scheduleCheckTimer];
  16. }
  17.  
  18. -(NSDate*) nextCheckDate {
  19.  
  20. NSCalendar *gregorian = [[[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar] autorelease];
  21.  
  22. NSDateComponents* dateComponents = [gregorian components: kCFCalendarUnitEra |
  23. kCFCalendarUnitYear |
  24. kCFCalendarUnitMonth |
  25. kCFCalendarUnitDay |
  26. kCFCalendarUnitHour |
  27. kCFCalendarUnitMinute |
  28. kCFCalendarUnitSecond fromDate: [NSDate date]];
  29.  
  30.  
  31. dateComponents.hour = 0;
  32. dateComponents.minute = 0;
  33. dateComponents.second = 0;
  34. dateComponents.day = dateComponents.day + 1;
  35.  
  36. return [gregorian dateFromComponents: dateComponents];
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement