Daily and weekly iOS reminders
// Update the prompt at every day
-(Void) alertByDay {
NSDate * date = [NSDate date];
NSCalendar * calendar = [NSCalendar currentCalendar];
NSDateComponents * comp = [calendar components :( NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit) fromDate: date];
Int hour = [comp hour];
Int min = [comp minute];
Int sec = [comp second];
Long int delayTime;
If (hour <10) {// time has not arrived
DelayTime = (21-hour) * 60*60-min * 60-sec;
} Else {
DelayTime = (24-hour + 10) * 60*60-min * 60-sec + 24*60*60;
}
NSDate * dates = [date dateByAddingTimeInterval: DelayTime];
UILocalNotification * localNoti = [[UILocalNotification alloc] init];
LocalNoti. alertAction = @ "View ";
LocalNoti. alertBody = [NSString stringWithString: @ "check if the software is updated"];
LocalNoti. fireDate = dates;
LocalNoti. repeatInterval = NSDayCalendarUnit;
[[UIApplication sharedApplication] schedulelocalpolicicatioN: localNoti];
[LocalNoti release];
}
// NSWeekdayCalendarUnit 1 to 7 1 indicates Sunday
-(Void) alertByWeek {
NSDate * date = [NSDate date];
NSCalendar * calendar = [NSCalendar currentCalendar];
NSDateComponents * comp = [calendar components :( NSWeekdayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit) fromDate: date];
Int weekDay = [comp weekday];
Int hour = [comp hour];
Int min = [comp minute];
Int sec = [comp second];
Long int delayTime;
BOOL figure = NO;
DelayTime = (24-hour + 10) * 60*60-min * 60-sec + 24*60*60;
If (weekDay = 1) {// if it is Sunday
If (hour <= 10) {// time has not reached 10
DelayTime = (21-hour) * 60*60-min * 60-sec;
Figure = YES;
}
}
If (! Figure ){
DelayTime = (weekDay-1) * 24*60*60 + hour * 60*60 + min * 60 + sec;
}
// Use one week-the time has passed + the time to be taken
DelayTime = 7*24*60 * 60-delayTime + 10*60*60;
NSDate * dates = [date dateByAddingTimeInterval: DelayTime];
UILocalNotification * localNoti = [[UILocalNotification alloc] init];
LocalNoti. alertAction = @ "View ";
LocalNoti. alertBody = [NSString stringWithString: @ "check if the software is updated"];
LocalNoti. fireDate = dates;
LocalNoti. repeatInterval = NSWeekCalendarUnit;
[[UIApplication sharedApplication] schedulelocalpolicicatioN: localNoti];
[LocalNoti release];
}