複数のローカル通知をスケジュールする方法。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日間から立ち往生しています。
どなたかご存知の方、助けてください....