本地通知每一天的特定日子

我需要创build一个特定时间的本地通知(例如在18.00)解雇了每星期的工作日(不是星期六和星期天),但我找不到示例或教程。 我想用swift2.1。 我怎样才能创build这个通知? 我的问题是正确定义通知

您可以使用NSDateComponents来创build本地通知的确切date。 下面是这个例子,我们如何使用确切的启动date创build本地通知:

 NSDate *now = [NSDate date]; NSCalendar *calendar = [NSCalendar currentCalendar]; NSDateComponents *components = [calendar components:NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitWeekOfYear|NSCalendarUnitWeekday fromDate:now];//get the required calendar units if (components.weekday>2) { components.weekOfYear+=1;//if already passed monday, make it next monday } components.weekday = 2;//Monday components.hour = 11; NSDate *fireDate = [calendar dateFromComponents:components]; UILocalNotification *localNotification = [[UILocalNotification alloc] init]; localNotification.fireDate = fireDate; localNotification.alertBody = @"alert message"; localNotification.applicationIconBadgeNumber = 1; localNotification.repeatInterval = NSCalendarUnitWeekOfYear; [[UIApplication sharedApplication] scheduleLocalNotification:localNotification]; 

在这段代码中,我将火灾date设置为每个星期一上午11点,并使用本地通知的repeatInterval将其设置为每周重复一次。 代码可能是错误的,需要testing,但我想这给你的基本思路,我也不快速编码,所以这是客观的C. 希望这可以帮助!