2013-02-28 53 views
0

我想在我的AppDelegate上設置多個本地通知,就像這段代碼所顯示的一樣。這可能嗎?如何在我的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]]; 

}

謝謝!

回答

0

將通知的repeatInterval屬性設置爲NSWeekdayCalendarUnit。

+0

謝謝,但我如何設置它是從星期一到星期五?我不想讓它在週六或週日出現。再次感謝。 – esierr1 2013-02-28 20:42:18

+0

這是我設置它的方式:'UILocalNotification * notification = [[UILocalNotification alloc] init]; [通知setAlertBody:@「讓音樂播放」]; [notification setFireDate:dd.date]; notification.repeatInterval = NSWeekdayCalendarUnit;因爲有各種各樣的**通知**,所以我在最後添加了它們:'[application setScheduledLocalNotifications:[NSArray arrayWithObjects:notification,notification1,notification2,notification3,notification4, notification5,nil]];'有時它不會觸發。爲什麼? – esierr1 2013-03-13 21:58:54