每周重复报警

Repeat alarm on weekly basis

我正在实施警报应用程序。我坚持逻辑。如何在每周基础上重复闹钟,意味着如果用户选择了星期日,那么闹钟将在每个星期日响起...... 这是我的代码。

-(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. set it to NSWeekCalendarUnit

的重复间隔参数
localNotification.repeatInterval = NSWeekCalendarUnit;