我正在实施警报应用程序。我坚持逻辑。如何在每周基本上重复闹钟,意味着如果用户选择星期天而不是闹钟将在每个星期天响起... 这是我的代码。
-(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];
}
答案 0 :(得分:0)
您可以使用NSLocalNotification的重复间隔参数。将其设置为NSWeekCalendarUnit
localNotification.repeatInterval = NSWeekCalendarUnit;