Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set UILocalNotification for 30 consecutive days

I want to schedule UILocalNotificaion for 30 consecutive days at 8:00 AM daily and i want to implement that functionality with one UILocationNotification instance only. Here is my code to schedule local notification.

NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"HH:mm"];
NSDate *date = [[NSDate alloc] init];
date = [formatter dateFromString:@"08:00"];
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
localNotification.fireDate = date;
localNotification.timeZone=[NSTimeZone defaultTimeZone];
localNotification.alertBody = @"You just received a local notification";
localNotification.alertAction = @"View Details";
localNotification.soundName = UILocalNotificationDefaultSoundName;
localNotification.repeatInterval = NSDayCalendarUnit;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
[formatter release];
[date release];

It will fire daily notifications forever at 08:00AM, but i want to be notified for 30 consecutive days only. The easiest solution is to fire 30 UILocalNotifications but i want to do that with 1 UILocalNotification instance. How can i do that? Please help.

like image 936
Shahid Iqbal Avatar asked Oct 02 '22 13:10

Shahid Iqbal


1 Answers

In UILocalNotification userInfo property save NSDate object when you create Notification. When you open Notification, check with the current date with date in userinfo . If there is difference is more than 30 days you can cancel your local notification.

like image 112
KAREEM MAHAMMED Avatar answered Oct 11 '22 13:10

KAREEM MAHAMMED