如何安排多个本地通知。在 iOS 10UILocalNotification
中更改为UNUserNotificationCenter
.
但我没有得到如何根据日期/时间添加多个通知。以及如何在单击通知栏中的特定通知时处理该通知。
以下是我的代码片段:
//这是我的 App 委托方法 -------
#import <UserNotifications/UserNotifications.h>
@interface AppDelegate ()<UNUserNotificationCenterDelegate>
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
center.delegate = self;
[center requestAuthorizationWithOptions:(UNAuthorizationOptionBadge | UNAuthorizationOptionSound | UNAuthorizationOptionAlert)
completionHandler:^(BOOL granted, NSError * _Nullable error) {
if (!error) {
NSLog(@"request succeeded!");
}
}];
return YES;
}
//这是我的视图控制器 --------
// Local Notification -------
UNMutableNotificationContent *content = [[UNMutableNotificationContent alloc] init];
content.title = [NSString localizedUserNotificationStringForKey:@"Notification!" arguments:nil];
content.body = [NSString localizedUserNotificationStringForKey:@"This is local notification message!" arguments:nil];
content.userInfo = [content userInfo];
content.sound = [UNNotificationSound defaultSound];
/// 4. update application icon badge number
content.badge = @([[UIApplication sharedApplication] applicationIconBadgeNumber] + 1);
NSDateComponents* date = [[NSDateComponents alloc] init];
date.day = 26;
date.month = 10;
date.year = 2016;
date.hour = 14;
date.minute = time; // Here time is different different time I want to schedule notification.
NSLog(@"date : %@",date);
// Deliver the notification in five seconds.
UNCalendarNotificationTrigger* trigger = [UNCalendarNotificationTrigger triggerWithDateMatchingComponents:date repeats:NO];
UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:@"FiveSecond" content:content trigger:trigger];
/// 3. schedule localNotification
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
[center addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) {
if (!error) {
NSLog(@"add NotificationRequest succeeded!");
}
}];
我不知道如何添加多个通知以及如何处理。我从过去 2 天开始就被困住了。
请知道的人帮帮我....