如何在AppDelegate上设置多个本地通知?

时间:2013-02-28 17:52:18

标签: ios uilocalnotification

我想在AppDelegate上设置多个本地通知,就像此代码中显示的那样。这可能吗?

此外,我已在下面的代码中设置了此通知,但如何从周一到周五重复播放?

这是我的代码:

AppDelegate.m

- (void)applicationDidEnterBackground:(UIApplication *)application {
/*
 Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
 If your application supports background execution, called instead of applicationWillTerminate: when the user quits.
 */

NSCalendar *gregCalendar = [[NSCalendar alloc]initWithCalendarIdentifier:NSGregorianCalendar];

NSDateComponents *dateComponent = [gregCalendar components:NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSWeekdayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit fromDate:[NSDate date]];

[dateComponent setWeekday:5];
[dateComponent setHour:11];
[dateComponent setMinute:26];


UIDatePicker *dd = [[UIDatePicker alloc]init];
[dd setDate:[gregCalendar dateFromComponents:dateComponent]];



UILocalNotification *notification = [[UILocalNotification alloc]init];
[notification setAlertBody:@"Let the Music Play"];
[notification setFireDate:dd.date];
[notification setTimeZone:[NSTimeZone defaultTimeZone]];
[application setScheduledLocalNotifications:[NSArray arrayWithObject:notification]];

}

谢谢!

1 个答案:

答案 0 :(得分:0)

将通知的repeatInterval属性设置为NSWeekdayCalendarUnit。