Objective c 每天在特定时间安排UILocalNotification
我使用下面的代码在特定时间安排一个本地通知。但通知每分钟都在重复,而不是一天之后。我是否错过了任何通知设置。我的时区是(亚洲/加尔各答(IST)偏移量19800),并且使用iPhone 4sObjective c 每天在特定时间安排UILocalNotification,objective-c,ios7,uilocalnotification,nscalendar,Objective C,Ios7,Uilocalnotification,Nscalendar,我使用下面的代码在特定时间安排一个本地通知。但通知每分钟都在重复,而不是一天之后。我是否错过了任何通知设置。我的时区是(亚洲/加尔各答(IST)偏移量19800),并且使用iPhone 4s - (void)applicationDidEnterBackground:(UIApplication *)application { NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar] ; NSDate
- (void)applicationDidEnterBackground:(UIApplication *)application
{
NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar] ;
NSDate *now = [NSDate date];
NSDateComponents *components = [calendar components:(NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute) fromDate:now];
[components setHour:12];
[components setMinute:00];
UILocalNotification *notification = [[UILocalNotification alloc]init];
notification.fireDate = [calendar dateFromComponents:components];
[notification setAlertBody:@"U got notification!!!"];
// notification.soundName = UILocalNotificationDefaultSoundName;
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
}
您应该指定
repeatInterval
- (void)applicationDidEnterBackground:(UIApplication *)application
{
NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar] ;
NSDate *now = [NSDate date];
NSDateComponents *components = [calendar components:(NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute) fromDate:now];
[components setHour:12];
[components setMinute:00];
UILocalNotification *notification = [[UILocalNotification alloc]init];
notification.fireDate = [calendar dateFromComponents:components];
notification.repeatInterval = NSDayCalendarUnit;
[notification setAlertBody:@"U got notification!!!"];
// notification.soundName = UILocalNotificationDefaultSoundName;
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
}
使用localnotification的repeatinterval属性localnotification.repeatinterval=NSCalendarUnitDay;你也会得到帮助@[Sviatoslav Yakymiv]这意味着通知将在每天12:00触发?@Nitesh是的。当日期是数组的索引时,如何根据数组中的不同时间重复通知,以设置在数组中给定的时间自动每天通知我array@SviatoslavYakymiv如果我有小时数列和分钟数列,想每天重复一次,请看一下这个问题