Leon před 1 rokem
rodič
revize
663bb45bc4

+ 1 - 1
ios/AppDelegate.mm

@@ -130,7 +130,7 @@ static NSString *const kRNConcurrentRoot = @"concurrentRoot";
 - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
 {
 //  return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
-#if DEBUG
+#if DEBUGaaa
   return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"];
 #else
   return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];

+ 128 - 1
ios/NativeBridge.m

@@ -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++){

Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 1 - 1
ios/main.jsbundle


+ 57 - 1
src/features/daynight/DayNightSwiper.tsx

@@ -65,6 +65,9 @@ export default function DayNightSwiper(props: { count: number, schedule: any, ho
                     }
                 })
             }
+            if (process.env.TARO_ENV == 'rn') {
+                setLocalPush(data)
+            }
             setAuthInfo(data)
             updateDate(data)
             locationObj = data
@@ -75,6 +78,59 @@ export default function DayNightSwiper(props: { count: number, schedule: any, ho
         })
     }
 
+    function setLocalPush(data) {
+        const { sunrise, sunset, solar_noon } = data.local_push;
+        var list: any = [];
+        if (!data.has_address || !data.has_daylight) {
+            return;
+        }
+        if (data && (data as any).daylights) {
+            (data as any).daylights.map((item, index) => {
+                var dayDuration = ''
+                var nightDuration = ''
+                if (item.sunrise_ts && item.sunset_ts) {
+                    dayDuration = TimeFormatter.durationFormate(item.sunset_ts, item.sunrise_ts, true)
+                }
+                if (index + 1 < (data as any).daylights.length - 1) {
+                    var nextObj = (data as any).daylights[index + 1];
+                    if (nextObj.sunrise_ts && item.sunset_ts) {
+                        nightDuration = TimeFormatter.durationFormate(nextObj.sunrise_ts, item.sunset_ts, true)
+                    }
+                }
+
+                if (sunrise && item.sunrise_ts) {
+                    list.push({
+                        category_id: 'REMINDER_SUN_RISE',
+                        title: 'Sunrise',
+                        body: `Daylight lasts ${dayDuration}`,
+                        timestamp: item.sunrise_ts
+                    })
+                }
+                if (sunset && item.sunset_ts) {
+                    list.push({
+                        category_id: 'REMINDER_SUN_SET',
+                        title: 'Sunset',
+                        body: `The night lasts ${nightDuration}`,
+                        timestamp: item.sunset_ts
+                    })
+                }
+                if (solar_noon && item.solar_noon_ts) {
+                    list.push({
+                        category_id: 'REMINDER_SUN_SOLAR_NOON',
+                        title: 'Solar Noon',
+                        body: 'The Sun is currently at its highest point in the sky for the day.',
+                        timestamp: item.solar_noon_ts
+                    })
+                }
+            })
+        }
+        if (process.env.TARO_ENV == 'rn') {
+            var Jto = require('react-native').NativeModules.NativeBridge;
+            Jto.addSunPush(list)
+        }
+
+    }
+
     function updateDate(data) {
         var today = new Date()
         if (data && data.daylights && data.daylights.length > 0) {
@@ -125,7 +181,7 @@ export default function DayNightSwiper(props: { count: number, schedule: any, ho
         indicatorColor='#ffffff66'
         indicatorActiveColor='#ffffff99'
         current={current}
-        style={{height:process.env.TARO_ENV=='weapp'?rpxToPx(204)+96+4:rpxToPx(204)+96+12+10}}
+        style={{ height: process.env.TARO_ENV == 'weapp' ? rpxToPx(204) + 96 + 4 : rpxToPx(204) + 96 + 12 + 10 }}
 
     >
         <SwiperItem>

+ 1 - 1
src/features/trackTimeDuration/actions/TrackTimeActions.tsx

@@ -160,7 +160,7 @@ export const getLocalPush = () => {
                     //     popInitialNotification: true,
                     //     // requestPermissions: true,
                     // });
-                    PushNotification.cancelAllLocalNotifications()
+                    // PushNotification.cancelAllLocalNotifications()
 
                     if (kIsIOS) {
                         var Jto = require('react-native').NativeModules.NativeBridge;

+ 6 - 0
src/pages/notification/setting.tsx

@@ -115,6 +115,8 @@ export default function Page() {
                                     }
                                 }
                             }
+                        }).then(res=>{
+                            global.swiperDayNightRefresh()
                         })
                     }}/>
                     </View>
@@ -130,6 +132,8 @@ export default function Page() {
                                     }
                                 }
                             }
+                        }).then(res=>{
+                            global.swiperDayNightRefresh()
                         })
                     }}/>
                     </View>
@@ -145,6 +149,8 @@ export default function Page() {
                                     }
                                 }
                             }
+                        }).then(res=>{
+                            global.swiperDayNightRefresh()
                         })
                     }}/>
                     </View>

Některé soubory nejsou zobrazeny, neboť je v těchto rozdílových datech změněno mnoho souborů