diff --git a/doric-iOS/Pod/Classes/DoricRegistry.h b/doric-iOS/Pod/Classes/DoricRegistry.h index 910affd5..99ef328e 100644 --- a/doric-iOS/Pod/Classes/DoricRegistry.h +++ b/doric-iOS/Pod/Classes/DoricRegistry.h @@ -40,6 +40,10 @@ NS_ASSUME_NONNULL_BEGIN - (Class)acquireViewNode:(NSString *)name; +- (void)setEnvironment:(NSString *)key variable:(id)value; + +- (NSDictionary *)environmentVariables; + + (void)register:(DoricLibrary *)library; @end diff --git a/doric-iOS/Pod/Classes/DoricRegistry.m b/doric-iOS/Pod/Classes/DoricRegistry.m index 1d0275cd..99e84348 100644 --- a/doric-iOS/Pod/Classes/DoricRegistry.m +++ b/doric-iOS/Pod/Classes/DoricRegistry.m @@ -78,7 +78,7 @@ @interface DoricRegistry () @property(nonatomic, strong) NSMutableDictionary *bundles; @property(nonatomic, strong) NSMutableDictionary *plugins; @property(nonatomic, strong) NSMutableDictionary *nodes; - +@property(nonatomic, strong) NSMutableDictionary *envVariables; @end @implementation DoricRegistry @@ -89,9 +89,10 @@ + (void)register:(DoricLibrary *)library { - (instancetype)init { if (self = [super init]) { - _bundles = [[NSMutableDictionary alloc] init]; - _plugins = [[NSMutableDictionary alloc] init]; - _nodes = [[NSMutableDictionary alloc] init]; + _bundles = [NSMutableDictionary new]; + _plugins = [NSMutableDictionary new]; + _nodes = [NSMutableDictionary new]; + _envVariables = [NSMutableDictionary new]; [self innerRegister]; [DoricLibraries.instance.libraries enumerateObjectsUsingBlock:^(DoricLibrary *obj, BOOL *stop) { [obj load:self]; @@ -153,4 +154,11 @@ - (Class)acquireViewNode:(NSString *)name { return self.nodes[name]; } +- (void)setEnvironment:(NSString *)key variable:(id)value { + self.envVariables[key] = value; +} + +- (NSDictionary *)environmentVariables { + return self.envVariables; +} @end diff --git a/doric-iOS/Pod/Classes/Engine/DoricJSEngine.m b/doric-iOS/Pod/Classes/Engine/DoricJSEngine.m index 6a3707a8..3b6488d7 100644 --- a/doric-iOS/Pod/Classes/Engine/DoricJSEngine.m +++ b/doric-iOS/Pod/Classes/Engine/DoricJSEngine.m @@ -23,7 +23,6 @@ #import "DoricJSEngine.h" #import "DoricJSExecutorProtocol.h" #import "DoricJSCoreExecutor.h" -#import "DoricJSRemoteExecutor.h" #import "DoricConstant.h" #import "DoricUtil.h" #import "DoricBridgeExtension.h" @@ -56,14 +55,20 @@ - (instancetype)init { - (void)initJSExecutor { __weak typeof(self) _self = self; NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary]; - [self.jsExecutor injectGlobalJSObject:INJECT_ENVIRONMENT obj:@{ + NSMutableDictionary *envDic = [@{ @"platform": @"iOS", @"platformVersion": [[UIDevice currentDevice] systemVersion], @"appName": infoDictionary[@"CFBundleName"], @"appVersion": infoDictionary[@"CFBundleShortVersionString"], @"screenWidth": @([[UIScreen mainScreen] bounds].size.width), @"screenHeight": @([[UIScreen mainScreen] bounds].size.height), + } mutableCopy]; + + [self.registry.environmentVariables enumerateKeysAndObjectsUsingBlock:^(NSString *key, id obj, BOOL *stop) { + envDic[key] = obj; }]; + + [self.jsExecutor injectGlobalJSObject:INJECT_ENVIRONMENT obj:[envDic copy]]; [self.jsExecutor injectGlobalJSObject:INJECT_LOG obj:^(NSString *type, NSString *message) { DoricLog(@"JS:%@", message); }];