每周重复报警

问题描述:

我正在执行报警应用。我坚持逻辑。如何每周基本重复闹钟,意思是如果用户选择星期日而不是闹钟,每个星期天都会响起... 这是我的代码。每周重复报警

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


} 

你可以使用重复的NSLocalNotification间隔参数。其设置为NSWeekCalendarUnit

localNotification.repeatInterval = NSWeekCalendarUnit; 
+0

这将每天重复闹铃,但我想,如果用户选择比周四将重复的明天和未来周四等等...... @ user3729525 – salmancs43

+0

“NSWeekCalendarUnit”星期为单位将启用报警每周不重复每天。 – Tina

+0

是的它的工作..但今天是星期三,如果用户选择警报日是星期五比我如何能实现这一点。 @Tina – salmancs43