本地通知每天和每月重复
Posted
技术标签:
【中文标题】本地通知每天和每月重复【英文标题】:Local notifications are repeat on every day and every month 【发布时间】:2014-04-21 10:15:07 【问题描述】:我有一个本地通知。像这样 ;
NSNumberFormatter *faturaSonOdemeGunuFormatter = [[NSNumberFormatter alloc] init];
[faturaSonOdemeGunuFormatter setNumberStyle:NSNumberFormatterNoStyle];
NSNumber *faturaSonOdemeGunuNumber = [faturaSonOdemeGunuFormatter numberFromString:_txtFaturaGunu.text];
NSDate *currentDate = [NSDate date];
NSCalendar * calendar = [NSCalendar currentCalendar];
[calendar setTimeZone:[NSTimeZone systemTimeZone]];
NSDateComponents* components = [calendar components:NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit fromDate:currentDate];
[components setTimeZone:[NSTimeZone systemTimeZone]];
[components setHour:12];
[components setMinute:40];
[components setDay: faturaSonOdemeGunuNumber.integerValue -3];
NSDate *test = [calendar dateFromComponents:components];
// Schedule the notification
UILocalNotification* localNotification = [[UILocalNotification alloc] init];
localNotification.fireDate = test;
localNotification.alertBody = [NSString stringWithFormat:@"%@ Faturanıza 3 gün kaldı.",_txtFaturaAdi.text];
localNotification.alertAction = @"Faturayı göster";
localNotification.timeZone = [NSTimeZone systemTimeZone];
localNotification.applicationIconBadgeNumber = [[UIApplication sharedApplication] applicationIconBadgeNumber] + 1;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
// Request to reload table view data
[[NSNotificationCenter defaultCenter] postNotificationName:@"reloadData" object:self];
此代码不会重复。我想在 faturaSonOdemeGunuNumber integerValue 日每个月重复本地通知。它应该从 sonOdemeGunuNumber -3 开始(例如用户写 17。它应该从 14 开始)并且它应该在每个月发出通知直到 faturaSonOdemeGunuNumber 的一天。我的意思是它应该每天继续通知用户,直到选定的那一天。 我该怎么做?
谢谢!
【问题讨论】:
【参考方案1】:添加这个:
localNotification.repeatInterval = kCFCalendarUnitMonth; //For monthly repeats
localNotification.repeatInterval = kCFCalendarUnitDay; //For daily repeats
【讨论】:
【参考方案2】:试试这个,
notification.repeatInterval= NSDayCalendarUnit; //For day
notification.repeatInterval= NSWeekCalendarUnit; //For Week
notification.repeatInterval= NSMonthCalendarUnit; //For Month
参考链接:http://useyourloaf.com/blog/2010/09/13/repeating-an-ios-local-notification.html
【讨论】:
以上是关于本地通知每天和每月重复的主要内容,如果未能解决你的问题,请参考以下文章