Objective c 每周重复报警
我正在实现报警应用程序。我被逻辑束缚住了。如何在每周基础上重复报警,意味着如果用户选择了星期天,则每个星期天都会响起报警。。。 这是我的密码Objective c 每周重复报警,objective-c,nsdate,uilocalnotification,alarm,nscalendar,Objective C,Nsdate,Uilocalnotification,Alarm,Nscalendar,我正在实现报警应用程序。我被逻辑束缚住了。如何在每周基础上重复报警,意味着如果用户选择了星期天,则每个星期天都会响起报警。。。 这是我的密码 -(void) repeataftersevendays: (NSString *) day { NSCalendar *calendar = [NSCalendar currentCalendar]; NSDateComponents *components = [[NSCalendar currentCalendar] componen
-(void) repeataftersevendays: (NSString *) day
{
NSCalendar *calendar = [NSCalendar currentCalendar];
NSDateComponents *components = [[NSCalendar currentCalendar] components:NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear fromDate:[NSDate date]];
[components setTimeZone:[NSTimeZone localTimeZone]];
[calendar setTimeZone: [NSTimeZone localTimeZone]];
sunday = [calendar dateByAddingUnit:NSCalendarUnitDay
value:4
toDate:[NSDate date]
options:0];;
NSLog(@"value is %@",sunday);
}
这是我的消防代码
-(void) scheduleLocalNotificationWithDate:(NSDate *)fireDate
{
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
localNotif.fireDate = fireDate;
localNotif.timeZone = [NSTimeZone localTimeZone];
localNotif.alertBody = @"Time to wake Up";
localNotif.alertAction = @"Show me";
localNotif.soundName = @"Tick-tock-sound.mp3";
localNotif.applicationIconBadgeNumber = 1;
localNotif.repeatInterval = kCFCalendarUnitDay;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
}
可以使用的重复间隔参数。设定为
这将重复警报每天,但我想,如果用户选择周四比它将重复明天和即将到来的周四等@user3729525“NSWeekCalendarUnit”周单位将使警报每周重复,而不是每天重复。是,它正在工作。。但今天是星期三,如果用户选择报警日是星期五,那么我如何才能做到这一点@你可以得到下星期五的日期,然后乘以天数来设置firedate。请参阅:
localNotification.repeatInterval = NSWeekCalendarUnit;