|
|
@@ -18,8 +18,6 @@
|
|
|
@implementation NativeBridge
|
|
|
@synthesize bridge = _bridge;
|
|
|
|
|
|
-// 定义一个自定义的 action 类型
|
|
|
-static NSString *const kMyCustomActionIdentifier = @"my_custom_action";
|
|
|
|
|
|
RCT_EXPORT_MODULE()
|
|
|
|
|
|
@@ -234,164 +232,78 @@ RCT_EXPORT_METHOD(addSunPush:(id)array){
|
|
|
[[UNUserNotificationCenter currentNotificationCenter] setNotificationCategories:[NSSet setWithArray:list]];
|
|
|
}
|
|
|
|
|
|
-//- (void)addFSNotifications:(id)array{
|
|
|
-// NSMutableArray *list = [NSMutableArray new];
|
|
|
-// for (int i=0;i<[array count];i++){
|
|
|
-// id detail = array[i];
|
|
|
-// NSString *mode = detail[@"mode"];
|
|
|
-//
|
|
|
-// if (![mode isEqualToString:@"RECURRING"]){
|
|
|
-// NSTimeInterval timestamp = [detail[@"once"] doubleValue]/1000; // 毫秒级时间戳
|
|
|
-// // 获取当前时间
|
|
|
-// NSDate *currentDate = [NSDate date];
|
|
|
-// // 计算当前时间与给定时间戳之间的时间差(秒)
|
|
|
-// NSTimeInterval timeInterval = timestamp - [currentDate timeIntervalSince1970];
|
|
|
-// if (timeInterval<0){
|
|
|
-// continue;
|
|
|
-// }
|
|
|
-// }
|
|
|
-//
|
|
|
-// //设置通知内容
|
|
|
-// UNMutableNotificationContent * content = [[UNMutableNotificationContent alloc] init];
|
|
|
-// content.title = detail[@"title"];
|
|
|
-// content.body = [NSString stringWithFormat:@"%@\nPress for actions >>",detail[@"body"]];
|
|
|
-// content.sound = [UNNotificationSound defaultSound];
|
|
|
-// content.badge = @([UIApplication sharedApplication].applicationIconBadgeNumber + 1);
|
|
|
-// if (@available(iOS 15.0,*)){
|
|
|
-// content.interruptionLevel = UNNotificationInterruptionLevelActive;
|
|
|
-// }
|
|
|
-//
|
|
|
-// NSString *category_id = detail[@"category_id"];
|
|
|
-// NSString *message_id = detail[@"id"];
|
|
|
-//
|
|
|
-//
|
|
|
-// NSArray *actions;
|
|
|
-// if ([category_id isEqualToString:@"REMINDER_FS_START_FAST"]||[category_id isEqualToString:@"REMINDER_FS_START_SLEEP"]){
|
|
|
-// //消息的处理按钮
|
|
|
-// UNNotificationAction *action1 = [UNNotificationAction actionWithIdentifier:@"START_TIMER_NOW" title:@"Start timer now with 1-tap" options:UNNotificationActionOptionForeground];
|
|
|
-//
|
|
|
-// UNNotificationAction *action2 = [UNNotificationAction actionWithIdentifier:@"PICK_EARLIER_START" title:@"Pick an earlier start" options:UNNotificationActionOptionForeground];
|
|
|
-//
|
|
|
-// UNNotificationAction *action3 = [UNNotificationAction actionWithIdentifier:@"SKIP" title:@"Skip" options:UNNotificationActionOptionAuthenticationRequired];
|
|
|
-//
|
|
|
-// actions = @[action1,action2,action3];
|
|
|
-// }
|
|
|
-// else if([category_id isEqualToString:@"REMINDER_FS_END_FAST"]||[category_id isEqualToString:@"REMINDER_FS_END_SLEEP"]){
|
|
|
-// //消息的处理按钮
|
|
|
-// UNNotificationAction *action1 = [UNNotificationAction actionWithIdentifier:@"END_TIMER_NOW" title:@"End timer now with 1-tap" options:UNNotificationActionOptionForeground];
|
|
|
-//
|
|
|
-// UNNotificationAction *action2 = [UNNotificationAction actionWithIdentifier:@"PICK_EARLIER_END" title:@"Pick an earlier end" options:UNNotificationActionOptionForeground];
|
|
|
-//
|
|
|
-// UNNotificationAction *action3 = [UNNotificationAction actionWithIdentifier:@"SKIP" title:@"Skip" options:UNNotificationActionOptionAuthenticationRequired];
|
|
|
-//
|
|
|
-// actions = @[action1,action2,action3];
|
|
|
-// }
|
|
|
-// else if ([category_id isEqualToString:@"REMINDER_FS_START_FAST_T2"]||
|
|
|
-// [category_id isEqualToString:@"REMINDER_FS_START_FAST_T3"]||
|
|
|
-// [category_id isEqualToString:@"REMINDER_FS_START_FAST_T4"]||
|
|
|
-// [category_id isEqualToString:@"REMINDER_FS_START_SLEEP_T3"]||
|
|
|
-// [category_id isEqualToString:@"REMINDER_FS_START_SLEEP_T4"]||
|
|
|
-// [category_id isEqualToString:@"REMINDER_FS_END_SLEEP_T4"]){
|
|
|
-// UNNotificationAction *action2 = [UNNotificationAction actionWithIdentifier:@"LOG_MY_TIMES" title:@"Log my times" options:UNNotificationActionOptionForeground];
|
|
|
-//
|
|
|
-// UNNotificationAction *action3 = [UNNotificationAction actionWithIdentifier:@"SKIP" title:@"Skip" options:UNNotificationActionOptionAuthenticationRequired];
|
|
|
-//
|
|
|
-// actions = @[action2,action3];
|
|
|
-// }
|
|
|
-//
|
|
|
-// NSDate *currentDate = [NSDate date];
|
|
|
-// NSString *strID = [NSString stringWithFormat:@"%f",[currentDate timeIntervalSince1970]];
|
|
|
-// UNNotificationCategory *categroy = [UNNotificationCategory categoryWithIdentifier:strID actions:actions intentIdentifiers:@[] options:UNNotificationCategoryOptionCustomDismissAction];
|
|
|
-// [list addObject:categroy];
|
|
|
-// // [[UNUserNotificationCenter currentNotificationCenter] setNotificationCategories:[NSSet setWithObject:categroy]];
|
|
|
-//
|
|
|
-// content.categoryIdentifier = strID;//category_id;
|
|
|
-//
|
|
|
-// if ([mode isEqualToString:@"RECURRING"]){
|
|
|
-// //设置推送的触发机制
|
|
|
-// NSArray *timeArray = [detail[@"recurring"][@"time"] componentsSeparatedByString:@":"];
|
|
|
-// NSInteger hour = [[timeArray objectAtIndex:0] integerValue];
|
|
|
-// NSInteger minute = [[timeArray objectAtIndex:1] integerValue];
|
|
|
-// NSInteger second = [[timeArray objectAtIndex:2] integerValue];
|
|
|
-//
|
|
|
-// // 2. 设置触发条件
|
|
|
-// NSDateComponents *dateComponents = [[NSDateComponents alloc] init];
|
|
|
-// dateComponents.hour = hour;
|
|
|
-// dateComponents.minute = minute;
|
|
|
-// dateComponents.second = second;
|
|
|
-// UNCalendarNotificationTrigger *trigger = [UNCalendarNotificationTrigger triggerWithDateMatchingComponents:dateComponents repeats:YES];
|
|
|
-//
|
|
|
-//
|
|
|
-// NSString * identifier = [NSString stringWithFormat:@"REMINDER_FS_%@",message_id];
|
|
|
-// UNNotificationRequest * request = [UNNotificationRequest requestWithIdentifier:identifier content:content trigger:trigger];
|
|
|
-// [[UNUserNotificationCenter currentNotificationCenter] addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) {
|
|
|
-//
|
|
|
-// }];
|
|
|
-// }
|
|
|
-// else {
|
|
|
-// NSTimeInterval timestamp = [detail[@"once"] doubleValue]/1000; // 毫秒级时间戳
|
|
|
-// // 获取当前时间
|
|
|
-// NSDate *currentDate = [NSDate date];
|
|
|
-// // 计算当前时间与给定时间戳之间的时间差(秒)
|
|
|
-// NSTimeInterval timeInterval = timestamp - [currentDate timeIntervalSince1970];
|
|
|
-//
|
|
|
-// UNTimeIntervalNotificationTrigger * trigger = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:timeInterval repeats:NO];
|
|
|
-// NSString * identifier = [NSString stringWithFormat:@"REMINDER_FS_%@",message_id];
|
|
|
-// UNNotificationRequest * request = [UNNotificationRequest requestWithIdentifier:identifier content:content trigger:trigger];
|
|
|
-// [[UNUserNotificationCenter currentNotificationCenter] addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) {
|
|
|
-//
|
|
|
-// }];
|
|
|
-// }
|
|
|
-// }
|
|
|
-//
|
|
|
-// [[UNUserNotificationCenter currentNotificationCenter] setNotificationCategories:[NSSet setWithArray:list]];
|
|
|
-//}
|
|
|
-
|
|
|
-RCT_EXPORT_METHOD(addLocalPush:(id)array){
|
|
|
- dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
+- (void)addFSNotifications:(id)array{
|
|
|
+ NSMutableArray *list = [NSMutableArray new];
|
|
|
+ for (int i=0;i<[array count];i++){
|
|
|
+ id detail = array[i];
|
|
|
+ NSString *mode = detail[@"mode"];
|
|
|
|
|
|
- UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
|
|
|
- [center getPendingNotificationRequestsWithCompletionHandler:^(NSArray<UNNotificationRequest *> * _Nonnull requests) {
|
|
|
- NSMutableArray *ids = [NSMutableArray new];
|
|
|
- for (int i=0;i<requests.count;i++){
|
|
|
- UNNotificationRequest *request = requests[i];
|
|
|
- if ([request.identifier hasPrefix:@"REMINDER_FS_"]){
|
|
|
- [ids addObject:request.identifier];
|
|
|
- }
|
|
|
+ if (![mode isEqualToString:@"RECURRING"]){
|
|
|
+ NSTimeInterval timestamp = [detail[@"once"] doubleValue]/1000; // 毫秒级时间戳
|
|
|
+ // 获取当前时间
|
|
|
+ NSDate *currentDate = [NSDate date];
|
|
|
+ // 计算当前时间与给定时间戳之间的时间差(秒)
|
|
|
+ NSTimeInterval timeInterval = timestamp - [currentDate timeIntervalSince1970];
|
|
|
+ if (timeInterval<0){
|
|
|
+ continue;
|
|
|
}
|
|
|
- [center removePendingNotificationRequestsWithIdentifiers:ids];
|
|
|
- [center removeAllDeliveredNotifications];
|
|
|
- [center removeAllPendingNotificationRequests];
|
|
|
-
|
|
|
- [self addFSNotifications:array];
|
|
|
- }];
|
|
|
+ }
|
|
|
|
|
|
+ NSString *category_id = detail[@"category_id"];
|
|
|
+ NSString *message_id = detail[@"id"];
|
|
|
|
|
|
+ //设置通知内容
|
|
|
+ UNMutableNotificationContent * content = [[UNMutableNotificationContent alloc] init];
|
|
|
+ content.title = detail[@"title"];
|
|
|
+ content.body = [NSString stringWithFormat:@"%@\nPress for actions >>",detail[@"body"]];
|
|
|
+ content.sound = [UNNotificationSound defaultSound];
|
|
|
+ content.badge = @([UIApplication sharedApplication].applicationIconBadgeNumber + 1);
|
|
|
+ content.categoryIdentifier = category_id;
|
|
|
+ if (@available(iOS 15.0,*)){
|
|
|
+ content.interruptionLevel = UNNotificationInterruptionLevelActive;
|
|
|
+ }
|
|
|
|
|
|
- });
|
|
|
-}
|
|
|
-
|
|
|
-- (void)addFSNotifications:(id)array{
|
|
|
- NSMutableArray *list = [NSMutableArray new];
|
|
|
- for (int i=0;i<1;i++){
|
|
|
- id detail = array[i];
|
|
|
- NSString *mode = detail[@"mode"];
|
|
|
|
|
|
- NSDate *currentDate = [NSDate date];
|
|
|
- NSString *strID = [NSString stringWithFormat:@"%f",[currentDate timeIntervalSince1970]];
|
|
|
- UNNotificationAction *action = [UNNotificationAction actionWithIdentifier:strID title:@"Action Title" options:UNNotificationActionOptionAuthenticationRequired];
|
|
|
-
|
|
|
- // 接着定义一个分类,并将动作添加到分类中
|
|
|
- UNNotificationCategory *category = [UNNotificationCategory categoryWithIdentifier:strID actions:@[action] intentIdentifiers:@[] options:UNNotificationCategoryOptionCustomDismissAction];
|
|
|
-
|
|
|
- // 注册分类
|
|
|
- [[UNUserNotificationCenter currentNotificationCenter] setNotificationCategories:[NSSet setWithObjects:category, nil]];
|
|
|
-
|
|
|
- // 创建本地推送内容
|
|
|
- UNMutableNotificationContent *content = [[UNMutableNotificationContent alloc] init];
|
|
|
- content.title = @"Notification Title";
|
|
|
- content.body = @"This is the notification body";
|
|
|
- content.categoryIdentifier = strID; // 使用你刚刚定义的分类标识符
|
|
|
+
|
|
|
+
|
|
|
+ NSArray *actions;
|
|
|
+ if ([category_id isEqualToString:@"REMINDER_FS_START_FAST"]||[category_id isEqualToString:@"REMINDER_FS_START_SLEEP"]){
|
|
|
+ //消息的处理按钮
|
|
|
+ UNNotificationAction *action1 = [UNNotificationAction actionWithIdentifier:@"START_TIMER_NOW" title:@"Start timer now with 1-tap" options:UNNotificationActionOptionForeground];
|
|
|
+
|
|
|
+ UNNotificationAction *action2 = [UNNotificationAction actionWithIdentifier:@"PICK_EARLIER_START" title:@"Pick an earlier start" options:UNNotificationActionOptionForeground];
|
|
|
+
|
|
|
+ UNNotificationAction *action3 = [UNNotificationAction actionWithIdentifier:@"SKIP" title:@"Skip" options:UNNotificationActionOptionAuthenticationRequired];
|
|
|
+
|
|
|
+ actions = @[action1,action2,action3];
|
|
|
+ }
|
|
|
+ else if([category_id isEqualToString:@"REMINDER_FS_END_FAST"]||[category_id isEqualToString:@"REMINDER_FS_END_SLEEP"]){
|
|
|
+ //消息的处理按钮
|
|
|
+ UNNotificationAction *action1 = [UNNotificationAction actionWithIdentifier:@"END_TIMER_NOW" title:@"End timer now with 1-tap" options:UNNotificationActionOptionForeground];
|
|
|
+
|
|
|
+ UNNotificationAction *action2 = [UNNotificationAction actionWithIdentifier:@"PICK_EARLIER_END" title:@"Pick an earlier end" options:UNNotificationActionOptionForeground];
|
|
|
+
|
|
|
+ UNNotificationAction *action3 = [UNNotificationAction actionWithIdentifier:@"SKIP" title:@"Skip" options:UNNotificationActionOptionAuthenticationRequired];
|
|
|
+
|
|
|
+ actions = @[action1,action2,action3];
|
|
|
+ }
|
|
|
+ else if ([category_id isEqualToString:@"REMINDER_FS_START_FAST_T2"]||
|
|
|
+ [category_id isEqualToString:@"REMINDER_FS_START_FAST_T3"]||
|
|
|
+ [category_id isEqualToString:@"REMINDER_FS_START_FAST_T4"]||
|
|
|
+ [category_id isEqualToString:@"REMINDER_FS_START_SLEEP_T3"]||
|
|
|
+ [category_id isEqualToString:@"REMINDER_FS_START_SLEEP_T4"]||
|
|
|
+ [category_id isEqualToString:@"REMINDER_FS_END_SLEEP_T4"]){
|
|
|
+ UNNotificationAction *action2 = [UNNotificationAction actionWithIdentifier:@"LOG_MY_TIMES" title:@"Log my times" options:UNNotificationActionOptionForeground];
|
|
|
+
|
|
|
+ UNNotificationAction *action3 = [UNNotificationAction actionWithIdentifier:@"SKIP" title:@"Skip" options:UNNotificationActionOptionAuthenticationRequired];
|
|
|
+
|
|
|
+ actions = @[action2,action3];
|
|
|
+ }
|
|
|
+
|
|
|
+ UNNotificationCategory *categroy = [UNNotificationCategory categoryWithIdentifier:category_id actions:actions intentIdentifiers:@[] options:UNNotificationCategoryOptionCustomDismissAction];
|
|
|
+ [list addObject:categroy];
|
|
|
+ // [[UNUserNotificationCenter currentNotificationCenter] setNotificationCategories:[NSSet setWithObject:categroy]];
|
|
|
+
|
|
|
|
|
|
if ([mode isEqualToString:@"RECURRING"]){
|
|
|
//设置推送的触发机制
|
|
|
@@ -408,7 +320,7 @@ RCT_EXPORT_METHOD(addLocalPush:(id)array){
|
|
|
UNCalendarNotificationTrigger *trigger = [UNCalendarNotificationTrigger triggerWithDateMatchingComponents:dateComponents repeats:YES];
|
|
|
|
|
|
|
|
|
- NSString * identifier = strID;
|
|
|
+ NSString * identifier = [NSString stringWithFormat:@"REMINDER_FS_%@",message_id];
|
|
|
UNNotificationRequest * request = [UNNotificationRequest requestWithIdentifier:identifier content:content trigger:trigger];
|
|
|
[[UNUserNotificationCenter currentNotificationCenter] addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) {
|
|
|
|
|
|
@@ -422,7 +334,7 @@ RCT_EXPORT_METHOD(addLocalPush:(id)array){
|
|
|
NSTimeInterval timeInterval = timestamp - [currentDate timeIntervalSince1970];
|
|
|
|
|
|
UNTimeIntervalNotificationTrigger * trigger = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:timeInterval repeats:NO];
|
|
|
- NSString * identifier = [NSString stringWithFormat:@"REMINDER_FS_%@",@"sss"];
|
|
|
+ NSString * identifier = [NSString stringWithFormat:@"REMINDER_FS_%@",message_id];
|
|
|
UNNotificationRequest * request = [UNNotificationRequest requestWithIdentifier:identifier content:content trigger:trigger];
|
|
|
[[UNUserNotificationCenter currentNotificationCenter] addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) {
|
|
|
|
|
|
@@ -430,70 +342,22 @@ RCT_EXPORT_METHOD(addLocalPush:(id)array){
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-// [[UNUserNotificationCenter currentNotificationCenter] setNotificationCategories:[NSSet setWithArray:list]];
|
|
|
+ [[UNUserNotificationCenter currentNotificationCenter] setNotificationCategories:[NSSet setWithArray:list]];
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-RCT_EXPORT_METHOD(addLocalPushttt:(id)array){
|
|
|
+RCT_EXPORT_METHOD(addLocalPush:(id)array){
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
- return;
|
|
|
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
|
|
|
-// [center getPendingNotificationRequestsWithCompletionHandler:^(NSArray<UNNotificationRequest *> * _Nonnull requests) {
|
|
|
-// NSMutableArray *ids = [NSMutableArray new];
|
|
|
-// for (int i=0;i<requests.count;i++){
|
|
|
-// UNNotificationRequest *request = requests[i];
|
|
|
-// if ([request.identifier hasPrefix:@"REMINDER_FS_"]){
|
|
|
-// [ids addObject:request.identifier];
|
|
|
-// }
|
|
|
-// }
|
|
|
-// [center removePendingNotificationRequestsWithIdentifiers:ids];
|
|
|
-// [self addFSNotifications:array];
|
|
|
-// }];
|
|
|
-
|
|
|
- [center removeAllPendingNotificationRequests];
|
|
|
-
|
|
|
- UNMutableNotificationContent * content = [[UNMutableNotificationContent alloc] init];
|
|
|
- content.title = @"aa";
|
|
|
- content.body = @"bb";
|
|
|
- content.sound = [UNNotificationSound defaultSound];
|
|
|
- content.badge = @([UIApplication sharedApplication].applicationIconBadgeNumber + 1);
|
|
|
- if (@available(iOS 15.0,*)){
|
|
|
- content.interruptionLevel = UNNotificationInterruptionLevelActive;
|
|
|
- }
|
|
|
-
|
|
|
- UNNotificationAction *customAction = [UNNotificationAction actionWithIdentifier:@"zzzz1"
|
|
|
- title:@"Custom Action"
|
|
|
- options:UNNotificationActionOptionNone];
|
|
|
-
|
|
|
- UNNotificationCategory *categroy = [UNNotificationCategory categoryWithIdentifier:@"my_category"
|
|
|
- actions:@[customAction]
|
|
|
- intentIdentifiers:@[]
|
|
|
- options:UNNotificationCategoryOptionCustomDismissAction];
|
|
|
-
|
|
|
-
|
|
|
- NSMutableArray *list = [NSMutableArray new];
|
|
|
- [list addObject:categroy];
|
|
|
-
|
|
|
- id detail = array[0];
|
|
|
- //设置推送的触发机制
|
|
|
- NSArray *timeArray = [detail[@"recurring"][@"time"] componentsSeparatedByString:@":"];
|
|
|
- NSInteger hour = [[timeArray objectAtIndex:0] integerValue];
|
|
|
- NSInteger minute = [[timeArray objectAtIndex:1] integerValue];
|
|
|
- NSInteger second = [[timeArray objectAtIndex:2] integerValue];
|
|
|
-
|
|
|
- // 2. 设置触发条件
|
|
|
- NSDateComponents *dateComponents = [[NSDateComponents alloc] init];
|
|
|
- dateComponents.hour = hour;
|
|
|
- dateComponents.minute = minute;
|
|
|
- dateComponents.second = second;
|
|
|
- UNCalendarNotificationTrigger *trigger = [UNCalendarNotificationTrigger triggerWithDateMatchingComponents:dateComponents repeats:YES];
|
|
|
-
|
|
|
- [[UNUserNotificationCenter currentNotificationCenter] setNotificationCategories:[NSSet setWithArray:list]];
|
|
|
-
|
|
|
- NSString * identifier = [NSString stringWithFormat:@"REMINDER_FS_%@",@"aaa"];
|
|
|
- UNNotificationRequest * request = [UNNotificationRequest requestWithIdentifier:identifier content:content trigger:trigger];
|
|
|
- [[UNUserNotificationCenter currentNotificationCenter] addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) {
|
|
|
-
|
|
|
+ [center getPendingNotificationRequestsWithCompletionHandler:^(NSArray<UNNotificationRequest *> * _Nonnull requests) {
|
|
|
+ NSMutableArray *ids = [NSMutableArray new];
|
|
|
+ for (int i=0;i<requests.count;i++){
|
|
|
+ UNNotificationRequest *request = requests[i];
|
|
|
+ if ([request.identifier hasPrefix:@"REMINDER_FS_"]){
|
|
|
+ [ids addObject:request.identifier];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ [center removePendingNotificationRequestsWithIdentifiers:ids];
|
|
|
+ [self addFSNotifications:array];
|
|
|
}];
|
|
|
|
|
|
|
|
|
@@ -501,49 +365,6 @@ RCT_EXPORT_METHOD(addLocalPushttt:(id)array){
|
|
|
});
|
|
|
}
|
|
|
|
|
|
-- (void)registerNotificationActions {
|
|
|
- UNNotificationAction *customAction = [UNNotificationAction actionWithIdentifier:kMyCustomActionIdentifier
|
|
|
- title:@"Custom Action"
|
|
|
- options:UNNotificationActionOptionNone];
|
|
|
-
|
|
|
- UNNotificationCategory *category = [UNNotificationCategory categoryWithIdentifier:@"my_category"
|
|
|
- actions:@[customAction]
|
|
|
- intentIdentifiers:@[]
|
|
|
- options:UNNotificationCategoryOptionNone];
|
|
|
-
|
|
|
- UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
|
|
|
- [center setNotificationCategories:[NSSet setWithObject:category]];
|
|
|
-}
|
|
|
-
|
|
|
-// 创建并发送本地通知
|
|
|
-- (void)scheduleLocalNotification {
|
|
|
- UNMutableNotificationContent *content = [[UNMutableNotificationContent alloc] init];
|
|
|
- content.title = @"Local Notification";
|
|
|
- content.body = @"This is a local notification with a custom action.";
|
|
|
- content.sound = [UNNotificationSound defaultSound];
|
|
|
- content.categoryIdentifier = @"my_category";
|
|
|
-
|
|
|
- UNTimeIntervalNotificationTrigger *trigger = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:10 repeats:NO];
|
|
|
-
|
|
|
- UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:@"my_notification"
|
|
|
- content:content
|
|
|
- trigger:trigger];
|
|
|
-
|
|
|
- UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
|
|
|
- [self registerNotificationActions];
|
|
|
-// [center addNotificationRequest:request withCompletionHandler:nil];
|
|
|
-}
|
|
|
-
|
|
|
-// 处理自定义 action 的点击事件
|
|
|
-- (void)userNotificationCenter:(UNUserNotificationCenter *)center
|
|
|
-didReceiveNotificationResponse:(UNNotificationResponse *)response
|
|
|
- withCompletionHandler:(void(^)(void))completionHandler {
|
|
|
- if ([response.actionIdentifier isEqualToString:kMyCustomActionIdentifier]) {
|
|
|
- NSLog(@"Custom action was tapped!");
|
|
|
- }
|
|
|
- completionHandler();
|
|
|
-}
|
|
|
-
|
|
|
|
|
|
@end
|
|
|
|