Daily and weekly iOS reminders

Source: Internet
Author: User

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];

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.