报警中重复功能

时间:2016-02-16 08:40:03

标签: ios nsdate uilocalnotification

我是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 mehtod

-(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天我一直坚持下去。我知道我的问题是重复但我不确定如何实现该逻辑。提前谢谢。

1 个答案:

答案 0 :(得分:0)

更改

if [ -d /proc/*/task/$TID ]; then echo found; fi

dateFormatter.timeZone = [NSTimeZone defaultTimeZone];

并查看this教程,了解重复功能。