Advertisement
aamaa

local

Jul 1st, 2015
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. times = [[NSMutableArray alloc]initWithObjects:@"02:06 PM",@"2:17 PM", nil];
  2.  
  3. for (NSString * arrDay in times) {
  4.  
  5.  
  6. NSDate *date = [NSDate date];
  7.  
  8. NSCalendar *gregorian = [NSCalendar currentCalendar];
  9. NSDateComponents *dateComponents = [gregorian components:(NSDayCalendarUnit|NSMonthCalendarUnit|NSYearCalendarUnit) fromDate:date];
  10. NSInteger day = [dateComponents day];
  11. NSInteger month = [dateComponents month];
  12. NSInteger year = [dateComponents year];
  13. NSString * dayTime1=[NSString stringWithFormat:@"%li-%li-%li %@",(long)day,(long)month,(long)year,arrDay];
  14.  
  15. NSDateFormatter* df = [[NSDateFormatter alloc] init];
  16. [df setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"]];
  17. [df setTimeZone:[NSTimeZone defaultTimeZone"]];
  18. [df setDateFormat:@"dd-MM-yyyy hh:mm a"];
  19. NSDate* newDate = [df dateFromString:dayTime1];
  20.  
  21. [df setDateFormat:@"dd-MM-yyyy HH:mm a"];
  22.  
  23.  
  24.  
  25. [self scheduleNotificationForDate:newDate];
  26.  
  27. -(void) scheduleNotificationForDate: (NSDate*)date {
  28. [[UIApplication sharedApplication] cancelAllLocalNotifications];
  29.  
  30. UILocalNotification *localNotification = [[UILocalNotification alloc] init];
  31. localNotification.fireDate = date;
  32.  
  33. localNotification.timeZone = [NSTimeZone defaultTimeZone];
  34. localNotification.alertBody = @"Your Notification Text";
  35. localNotification.alertAction = NSLocalizedString(@"View details", nil);
  36. NSLog(@"Notification will be shown on: %@ ",localNotification.fireDate);
  37.  
  38. localNotification.soundName = UILocalNotificationDefaultSoundName;
  39. localNotification.applicationIconBadgeNumber = -1;
  40.  
  41. [[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement