From 7247d99db6718df8e72fea47f04e88174bf73ff9 Mon Sep 17 00:00:00 2001 From: "pengfei.zhou" Date: Tue, 10 Dec 2019 20:30:43 +0800 Subject: [PATCH] feat:add Environment --- Pod/Classes/Engine/DoricJSEngine.m | 12 ++++++++++-- Pod/Classes/Util/DoricConstant.h | 2 +- Pod/Classes/Util/DoricConstant.m | 1 + 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Pod/Classes/Engine/DoricJSEngine.m b/Pod/Classes/Engine/DoricJSEngine.m index 12984ea8..532701aa 100644 --- a/Pod/Classes/Engine/DoricJSEngine.m +++ b/Pod/Classes/Engine/DoricJSEngine.m @@ -55,12 +55,20 @@ - (instancetype)init { - (void)initJSExecutor { __weak typeof(self) _self = self; - + NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary]; + [self.jsExecutor injectGlobalJSObject:INJECT_ENVIRONMENT obj:@{ + @"platform": @"iOS", + @"platformVersion": [[UIDevice currentDevice] systemVersion], + @"appName": infoDictionary[@"CFBundleName"], + @"appVersion": infoDictionary[@"CFBundleShortVersionString"], + @"screenWidth": @([[UIScreen mainScreen] bounds].size.width), + @"screenHeight": @([[UIScreen mainScreen] bounds].size.height), + }]; [self.jsExecutor injectGlobalJSObject:INJECT_LOG obj:^(NSString *type, NSString *message) { DoricLog(@"JS:%@", message); }]; [self.jsExecutor injectGlobalJSObject:INJECT_EMPTY obj:^() { - + }]; [self.jsExecutor injectGlobalJSObject:INJECT_REQUIRE obj:^(NSString *name) { __strong typeof(_self) self = _self; diff --git a/Pod/Classes/Util/DoricConstant.h b/Pod/Classes/Util/DoricConstant.h index 06b34fd2..354ca050 100644 --- a/Pod/Classes/Util/DoricConstant.h +++ b/Pod/Classes/Util/DoricConstant.h @@ -26,7 +26,7 @@ extern NSString *const DORIC_BUNDLE_SANDBOX; extern NSString *const DORIC_BUNDLE_LIB; extern NSString *const DORIC_MODULE_LIB; - +extern NSString *const INJECT_ENVIRONMENT; extern NSString *const INJECT_LOG; extern NSString *const INJECT_REQUIRE; extern NSString *const INJECT_TIMER_SET; diff --git a/Pod/Classes/Util/DoricConstant.m b/Pod/Classes/Util/DoricConstant.m index 09a742a4..b7b30543 100644 --- a/Pod/Classes/Util/DoricConstant.m +++ b/Pod/Classes/Util/DoricConstant.m @@ -26,6 +26,7 @@ NSString *const DORIC_BUNDLE_LIB = @"doric-lib"; NSString *const DORIC_MODULE_LIB = @"doric"; +NSString *const INJECT_ENVIRONMENT = @"Environment"; NSString *const INJECT_LOG = @"nativeLog"; NSString *const INJECT_REQUIRE = @"nativeRequire";