|
|
@@ -149,11 +149,138 @@ RCT_EXPORT_METHOD(clearNotification){
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+RCT_EXPORT_METHOD(addSunPushzzz:(id)array){
|
|
|
+ dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
+ UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
|
|
|
+ // [center removeAllPendingNotificationRequests];
|
|
|
+ [center getPendingNotificationRequestsWithCompletionHandler:^(NSArray<UNNotificationRequest *> * _Nonnull requests) {
|
|
|
+ NSLog(@"%d",requests.count);
|
|
|
+ }];
|
|
|
+ // [center removeAllPendingNotificationRequests];
|
|
|
+ [center removePendingNotificationRequestsWithIdentifiers:@[
|
|
|
+ @"REMINDER_SUN_RISE",
|
|
|
+ @"REMINDER_SUN_SET",
|
|
|
+ @"REMINDER_SUN_SOLAR_NOON"
|
|
|
+ ]];
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+RCT_EXPORT_METHOD(addSunPush:(id)array){
|
|
|
+ dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
+ UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
|
|
|
+// [center removeAllPendingNotificationRequests];
|
|
|
+ [center getPendingNotificationRequestsWithCompletionHandler:^(NSArray<UNNotificationRequest *> * _Nonnull requests) {
|
|
|
+ NSLog(@"%d",requests.count);
|
|
|
+ }];
|
|
|
+// [center removeAllPendingNotificationRequests];
|
|
|
+ [center removePendingNotificationRequestsWithIdentifiers:@[
|
|
|
+ @"REMINDER_SUN_RISE",
|
|
|
+ @"REMINDER_SUN_SET",
|
|
|
+ @"REMINDER_SUN_SOLAR_NOON"
|
|
|
+ ]];
|
|
|
+
|
|
|
+ NSMutableArray *ids = [NSMutableArray new];
|
|
|
+ for (int i =0;i<[array count];i++){
|
|
|
+ id detail = array[i];
|
|
|
+ [ids addObject:[NSString stringWithFormat:@"%@",detail[@"timestamp"]]];
|
|
|
+ }
|
|
|
+ [center removePendingNotificationRequestsWithIdentifiers:ids];
|
|
|
+
|
|
|
+ NSMutableArray *list = [NSMutableArray new];
|
|
|
+ NSUInteger count = [array count];
|
|
|
+ if (count>30){
|
|
|
+ count = 30;
|
|
|
+ }
|
|
|
+ for (int i=0;i<count;i++){
|
|
|
+ id detail = array[i];
|
|
|
+ NSTimeInterval timestamp = [detail[@"timestamp"] doubleValue]/1000; // 毫秒级时间戳
|
|
|
+ // 获取当前时间
|
|
|
+ NSDate *currentDate = [NSDate date];
|
|
|
+ // 计算当前时间与给定时间戳之间的时间差(秒)
|
|
|
+ NSTimeInterval timeInterval = timestamp - [currentDate timeIntervalSince1970];
|
|
|
+
|
|
|
+ if (timeInterval<0){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ NSString * identifier = detail[@"category_id"];
|
|
|
+ UNMutableNotificationContent * content = [[UNMutableNotificationContent alloc] init];
|
|
|
+ content.title = detail[@"title"];
|
|
|
+ content.body = detail[@"body"];
|
|
|
+ content.sound = [UNNotificationSound defaultSound];
|
|
|
+ content.badge = @([UIApplication sharedApplication].applicationIconBadgeNumber + 1);
|
|
|
+
|
|
|
+
|
|
|
+ UNNotificationCategory *categroy = [UNNotificationCategory categoryWithIdentifier:[NSString stringWithFormat:@"%@",detail[@"timestamp"]] actions:@[] intentIdentifiers:@[] options:UNNotificationCategoryOptionCustomDismissAction];
|
|
|
+ [list addObject:categroy];
|
|
|
+ // [[UNUserNotificationCenter currentNotificationCenter] setNotificationCategories:[NSSet setWithObject:categroy]];
|
|
|
+ content.categoryIdentifier = [NSString stringWithFormat:@"%@",detail[@"timestamp"]];
|
|
|
+
|
|
|
+ UNTimeIntervalNotificationTrigger * trigger = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:timeInterval repeats:NO];
|
|
|
+ UNNotificationRequest * request = [UNNotificationRequest requestWithIdentifier:[NSString stringWithFormat:@"%@",detail[@"timestamp"]] content:content trigger:trigger];
|
|
|
+ [[UNUserNotificationCenter currentNotificationCenter] addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) {
|
|
|
+
|
|
|
+ }];
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ [[UNUserNotificationCenter currentNotificationCenter] setNotificationCategories:[NSSet setWithArray:list]];
|
|
|
+// for (int i=0;i<7;i++){
|
|
|
+// id detail = array[i];
|
|
|
+// UNMutableNotificationContent * content = [[UNMutableNotificationContent alloc] init];
|
|
|
+// content.title = detail[@"title"];
|
|
|
+// content.body = detail[@"body"];
|
|
|
+// content.sound = [UNNotificationSound defaultSound];
|
|
|
+// content.badge = @([UIApplication sharedApplication].applicationIconBadgeNumber + 1);
|
|
|
+//
|
|
|
+// NSString *category_id = detail[@"category_id"];
|
|
|
+//
|
|
|
+// NSTimeInterval timestamp = [detail[@"timestamp"] doubleValue]/1000; // 毫秒级时间戳
|
|
|
+// // 获取当前时间
|
|
|
+// NSDate *currentDate = [NSDate date];
|
|
|
+// // 计算当前时间与给定时间戳之间的时间差(秒)
|
|
|
+// NSTimeInterval timeInterval = timestamp - [currentDate timeIntervalSince1970];
|
|
|
+//
|
|
|
+// if (timeInterval<0){
|
|
|
+// continue;
|
|
|
+// }
|
|
|
+//
|
|
|
+// UNNotificationCategory *categroy = [UNNotificationCategory categoryWithIdentifier:category_id actions:@[
|
|
|
+// [UNNotificationAction actionWithIdentifier:@"LOG_MY_TIMES" title:@"Log my times" options:UNNotificationActionOptionForeground]
|
|
|
+// ] intentIdentifiers:@[] options:UNNotificationCategoryOptionCustomDismissAction];
|
|
|
+// [list addObject:categroy];
|
|
|
+// // [[UNUserNotificationCenter currentNotificationCenter] setNotificationCategories:[NSSet setWithObject:categroy]];
|
|
|
+// content.categoryIdentifier = category_id;
|
|
|
+//
|
|
|
+// UNTimeIntervalNotificationTrigger * trigger = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:timeInterval repeats:NO];
|
|
|
+// NSString * identifier = detail[@"category_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(), ^{
|
|
|
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
|
|
|
- [center removeAllPendingNotificationRequests];
|
|
|
+// [center removeAllPendingNotificationRequests];
|
|
|
+ [center removePendingNotificationRequestsWithIdentifiers:@[
|
|
|
+ @"REMINDER_FS_START_FAST",
|
|
|
+ @"REMINDER_FS_START_SLEEP",
|
|
|
+ @"REMINDER_FS_END_FAST",
|
|
|
+ @"REMINDER_FS_END_SLEEP",
|
|
|
+ @"REMINDER_FS_START_FAST_T2",
|
|
|
+ @"REMINDER_FS_START_FAST_T3",
|
|
|
+ @"REMINDER_FS_START_FAST_T4",
|
|
|
+ @"REMINDER_FS_START_SLEEP_T3",
|
|
|
+ @"REMINDER_FS_START_SLEEP_T4",
|
|
|
+ @"REMINDER_FS_END_SLEEP_T4"
|
|
|
+ ]];
|
|
|
|
|
|
NSMutableArray *list = [NSMutableArray new];
|
|
|
for (int i=0;i<[array count];i++){
|