jjuser19jj
jjuser19jj

Reputation: 1699

Schedule a UILocalNotification every day at the same time

I want to fire a UILocalNotification every day at 6:00, 9:00, 12:00 for the next 20 days. I realize that this question is a very basic question, I would try to accomplish this with NSDateComponents, but then I realized that I could get problems when a month just has 28 days or the year changes. Thats why I ask: Has someone experience with such a task and could give me some hints?

Upvotes: 1

Views: 182

Answers (1)

Piyush
Piyush

Reputation: 1224

Create three different local notification with repeatInterval.

UILocalNotification* localNotification = [[UILocalNotification alloc] init];
localNotification.fireDate = date; // Specifly date and time for notification
localNotification.repeatInterval = NSCalendarUnitDay;
localNotification.alertBody = @"Notification";
localNotification.timeZone = [NSTimeZone defaultTimeZone];
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];

At time of 20 days cancel those notification.

[[UIApplication sharedApplication] cancelAllLocalNotifications];
   or
[[UIApplication sharedApplication] cancelLocalNotification:NOTIFICATION_ID];

Upvotes: 2

Related Questions