|
|
@@ -317,7 +317,7 @@ RCT_EXPORT_METHOD(addSunPush:(id)array){
|
|
|
UNCalendarNotificationTrigger *trigger = [UNCalendarNotificationTrigger triggerWithDateMatchingComponents:dateComponents repeats:YES];
|
|
|
|
|
|
|
|
|
- NSString * identifier = message_id;
|
|
|
+ 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) {
|
|
|
|
|
|
@@ -362,83 +362,6 @@ RCT_EXPORT_METHOD(addLocalPush:(id)array){
|
|
|
});
|
|
|
}
|
|
|
|
|
|
-RCT_EXPORT_METHOD(addLocalPush3:(id)detail){
|
|
|
- dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
- //设置通知内容
|
|
|
- UNMutableNotificationContent * content = [[UNMutableNotificationContent alloc] init];
|
|
|
- content.title = detail[@"title"];
|
|
|
- content.body = detail[@"body"];
|
|
|
-
|
|
|
- NSString *category_id = detail[@"category_id"];
|
|
|
- NSString *message_id = detail[@"id"];
|
|
|
- NSString *mode = detail[@"mode"];
|
|
|
-
|
|
|
- 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];
|
|
|
- }
|
|
|
-
|
|
|
- UNNotificationCategory *categroy = [UNNotificationCategory categoryWithIdentifier:category_id actions:actions intentIdentifiers:@[] options:UNNotificationCategoryOptionCustomDismissAction];
|
|
|
-
|
|
|
- [[UNUserNotificationCenter currentNotificationCenter] setNotificationCategories:[NSSet setWithObject:categroy]];
|
|
|
- content.categoryIdentifier = 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 = 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 = message_id;
|
|
|
- UNNotificationRequest * request = [UNNotificationRequest requestWithIdentifier:identifier content:content trigger:trigger];
|
|
|
- [[UNUserNotificationCenter currentNotificationCenter] addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) {
|
|
|
-
|
|
|
- }];
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- });
|
|
|
-}
|
|
|
|
|
|
@end
|
|
|
|