From cc1b4d92cbe3ebfa22ca8eadda70cd19458ec1c0 Mon Sep 17 00:00:00 2001 From: pengfeizhou Date: Tue, 23 Feb 2021 15:58:49 +0800 Subject: [PATCH] iOS:Timer key change from NSString to NSNumber --- doric-iOS/Pod/Classes/Engine/DoricJSEngine.m | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/doric-iOS/Pod/Classes/Engine/DoricJSEngine.m b/doric-iOS/Pod/Classes/Engine/DoricJSEngine.m index ea3cca11..84d710ff 100644 --- a/doric-iOS/Pod/Classes/Engine/DoricJSEngine.m +++ b/doric-iOS/Pod/Classes/Engine/DoricJSEngine.m @@ -42,7 +42,7 @@ - (void)onLog:(DoricLogType)type message:(NSString *)message { @end @interface DoricJSEngine () -@property(nonatomic, strong) NSMutableDictionary *timers; +@property(nonatomic, strong) NSMutableDictionary *timers; @property(nonatomic, strong) DoricBridgeExtension *bridgeExtension; @property(nonatomic, strong) NSDictionary *innerEnvironmentDictionary; @property(nonatomic, strong) NSThread *jsThread; @@ -170,19 +170,18 @@ - (void)initJSExecutor { [self.jsExecutor injectGlobalJSObject:INJECT_TIMER_SET obj:^(NSNumber *timerId, NSNumber *interval, NSNumber *isInterval) { __strong typeof(_self) self = _self; - NSString *timerId_str = [timerId stringValue]; BOOL repeat = [isInterval boolValue]; NSTimer *timer = [NSTimer timerWithTimeInterval:[interval doubleValue] / 1000 target:self selector:@selector(callbackTimer:) userInfo:@{@"timerId": timerId, @"repeat": isInterval} repeats:repeat]; - [self.timers setValue:timer forKey:timerId_str]; + self.timers[timerId] = timer; dispatch_async(dispatch_get_main_queue(), ^() { [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSRunLoopCommonModes]; }); }]; [self.jsExecutor injectGlobalJSObject:INJECT_TIMER_CLEAR - obj:^(NSString *timerId) { + obj:^(NSNumber *timerId) { __strong typeof(_self) self = _self; - NSTimer *timer = [self.timers valueForKey:timerId]; + NSTimer *timer = self.timers[timerId]; if (timer) { [self.timers removeObjectForKey:timerId]; dispatch_async(dispatch_get_main_queue(), ^{ @@ -284,7 +283,7 @@ - (void)callbackTimer:(NSTimer *)timer { message:[NSString stringWithFormat:@"Timer Callback error:%@", exception.reason]]; } if (![repeat boolValue]) { - [self.timers removeObjectForKey:[timerId stringValue]]; + [self.timers removeObjectForKey:timerId]; } }]; }