iOS:get environment information in main thread
This commit is contained in:
parent
8e79ce3bad
commit
99dd7f9231
@ -29,6 +29,7 @@
|
|||||||
@interface DoricJSEngine ()
|
@interface DoricJSEngine ()
|
||||||
@property(nonatomic, strong) NSMutableDictionary *timers;
|
@property(nonatomic, strong) NSMutableDictionary *timers;
|
||||||
@property(nonatomic, strong) DoricBridgeExtension *bridgeExtension;
|
@property(nonatomic, strong) DoricBridgeExtension *bridgeExtension;
|
||||||
|
@property(nonatomic, strong) NSDictionary *innerEnvironmentDictionary;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation DoricJSEngine
|
@implementation DoricJSEngine
|
||||||
@ -37,6 +38,18 @@ - (instancetype)init {
|
|||||||
if (self = [super init]) {
|
if (self = [super init]) {
|
||||||
_jsQueue = dispatch_queue_create("doric.jsengine", DISPATCH_QUEUE_SERIAL);
|
_jsQueue = dispatch_queue_create("doric.jsengine", DISPATCH_QUEUE_SERIAL);
|
||||||
_bridgeExtension = [[DoricBridgeExtension alloc] init];
|
_bridgeExtension = [[DoricBridgeExtension alloc] init];
|
||||||
|
dispatch_sync(dispatch_get_main_queue(), ^{
|
||||||
|
NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
|
||||||
|
_innerEnvironmentDictionary = @{
|
||||||
|
@"platform": @"iOS",
|
||||||
|
@"platformVersion": [[UIDevice currentDevice] systemVersion],
|
||||||
|
@"appName": infoDictionary[@"CFBundleName"],
|
||||||
|
@"appVersion": infoDictionary[@"CFBundleShortVersionString"],
|
||||||
|
@"screenWidth": @([[UIScreen mainScreen] bounds].size.width),
|
||||||
|
@"screenHeight": @([[UIScreen mainScreen] bounds].size.height),
|
||||||
|
@"statusBarHeight": @([[UIApplication sharedApplication] statusBarFrame].size.height),
|
||||||
|
};
|
||||||
|
});
|
||||||
dispatch_async(_jsQueue, ^() {
|
dispatch_async(_jsQueue, ^() {
|
||||||
self.timers = [[NSMutableDictionary alloc] init];
|
self.timers = [[NSMutableDictionary alloc] init];
|
||||||
[self initJSEngine];
|
[self initJSEngine];
|
||||||
@ -54,17 +67,7 @@ - (void)initJSEngine {
|
|||||||
|
|
||||||
- (void)initJSExecutor {
|
- (void)initJSExecutor {
|
||||||
__weak typeof(self) _self = self;
|
__weak typeof(self) _self = self;
|
||||||
NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
|
NSMutableDictionary *envDic = [self.innerEnvironmentDictionary mutableCopy];
|
||||||
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),
|
|
||||||
@"statusBarHeight": @([[UIApplication sharedApplication] statusBarFrame].size.height),
|
|
||||||
} mutableCopy];
|
|
||||||
|
|
||||||
[self.registry.environmentVariables enumerateKeysAndObjectsUsingBlock:^(NSString *key, id obj, BOOL *stop) {
|
[self.registry.environmentVariables enumerateKeysAndObjectsUsingBlock:^(NSString *key, id obj, BOOL *stop) {
|
||||||
envDic[key] = obj;
|
envDic[key] = obj;
|
||||||
}];
|
}];
|
||||||
|
Reference in New Issue
Block a user