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

时间:2021-09-11 23:09:45

I want to set up multiple Local Notifications, like the one shown on this code, on my AppDelegate. Is this possible?

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

Also, I have set up this notification shown on the code below, but how can I make repeat from Monday to Friday?

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

Here's my code:

这是我的代码:

AppDelegate.m

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]];

}

}

Thanks!

谢谢!

1 个解决方案

#1


0  

Set the repeatInterval property of the notification to NSWeekdayCalendarUnit.

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

#1


0  

Set the repeatInterval property of the notification to NSWeekdayCalendarUnit.

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