【发布时间】:2016-02-16 08:40:02
【问题描述】:
我是 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];
这是我的scheduledLocalNotificationmehtod
-(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 天开始,我一直坚持下去。我知道我的问题是重复的,但我不确定如何实现该逻辑。提前致谢。
【问题讨论】:
标签: ios nsdate uilocalnotification