【发布时间】:2012-04-30 03:30:06
【问题描述】:
我有这段代码用于每天午夜触发本地通知:
//Get todays midnight
NSDate *alertTime = [NSDate date];
NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar];
NSUInteger preservedComponents = (NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit);
alertTime = [calendar dateFromComponents:[calendar components:preservedComponents fromDate:alertTime]];
UIApplication *app = [UIApplication sharedApplication];
//Set up the local notification
UILocalNotification *notification = [[UILocalNotification alloc] init];
if(notification){
//Set fire date to alert time
notification.fireDate = alertTime;
//Set time zone to default
notification.timeZone = [NSTimeZone defaultTimeZone];
//Repeat the notification everyday (fires at same time
//as initial notification)
notification.repeatInterval = NSDayCalendarUnit;
// schedule notification
[app scheduleLocalNotification:notification];
NSLog(@"%@", notification.fireDate);
}
但是,我需要在每天 13:00 触发另一个本地通知。这是如何实现的?我不明白如何调整上面的代码来实现这一点..
非常感谢,
杰克
【问题讨论】:
-
观看我的回答,namaztimes 是我的数组,其中包含触发时间,在这段代码中,我必须每天触发 5 次本地通知(每天都这样),所以,根据你可以自定义它
标签: iphone objective-c ios uilocalnotification