警报中的重复功能

Repeat Functionality in Alarm

我是 iOS 的新手。我正在制作一个警报应用程序,我想实现重复功能。我搜索了很多,但不太了解如何执行此操作。我知道这是通过通知方法完成的。我被它困住了。请任何人告诉我解决方案。这是用户保存警报时我的代码。

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.timeZone = [NSTimeZone defaultTimeZone];
NSLog(@"dateformater %@",dateFormatter);
dateFormatter.timeStyle = NSDateFormatterShortStyle;
NSString * dateTimeString = [dateFormatter stringFromDate:timePicker.date];
NSLog(@"date time string %@",dateTimeString);

[dateFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:NSLocaleIdentifier]];
//[dateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"UTC"]];
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
datesArray = @[[dateFormatter stringFromDate:self.timePicker.date]];
NSLog(@"dates array is %@",datesArray);

[datesArray enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop)
{
    NSArray * repeatDays = [repeatResult componentsSeparatedByString:@","];
    for (NSString * days in repeatDays)
    {
        if ([days isEqualToString:@"Sun"])
        {
            [self getDateOfSpecificDay:1];

        }
        if ([days isEqualToString:@"Mon"])
        {
            [self getDateOfSpecificDay:2];

        }
        if ([days isEqualToString:@"Tue"])
        {
            [self getDateOfSpecificDay:3];

        }
        if ([days isEqualToString:@"Wed"])
        {
            [self getDateOfSpecificDay:4];

        }
        if ([days isEqualToString:@"Thu"])
        {
            [self getDateOfSpecificDay:5];

        }
        if ([days isEqualToString:@"Fri"])
        {
            [self getDateOfSpecificDay:6];

        }
        if ([days isEqualToString:@"Sat"])
        {
            [self getDateOfSpecificDay:7];

        }



    }





}];

AlarmObject * alarm = [[AlarmObject alloc] init];
alarm.repeatData = repeatResult;
alarm.clockDate = dateTimeString;

[self.delegate alarmSetting:alarm];
[self scheduleLocalNotificationWithDate:timePicker.date];
[self.navigationController popViewControllerAnimated:YES];

这是我的 scheduledLocalNotification 方法

-(void) scheduleLocalNotificationWithDate:(NSDate *)fireDate
{   

 UILocalNotification *localNotif = [[UILocalNotification alloc] init];
 localNotif.alertBody = @"Time to wake Up";
 localNotif.alertAction = @"Show me";
 localNotif.soundName = @"Tick-tock-sound.mp3";
 localNotif.applicationIconBadgeNumber = 1;
 localNotif.repeatInterval = NSCalendarUnitWeekOfYear;
NSLog(@"%@",[NSDate date]);
 [[UIApplication sharedApplication] scheduleLocalNotification:localNotif];`

过去 4 天我一直坚持使用它。我知道我的问题是重复的,但我不确定如何实现该逻辑。提前致谢。

改变

dateFormatter.timeZone = [NSTimeZone defaultTimeZone];

dateFormatter.timeZone = [NSTimeZone localTimeZone];

并查看 this 重复功能教程。