簡體   English   中英

如何在AppDelegate上設置多個本地通知?

[英]How can I set up multiple local notifications on my 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]];

}

謝謝!

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM