* [iOS] bugfix
Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/46910ade Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/46910ade Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/46910ade Branch: refs/heads/master Commit: 46910adedde4591dc38e8f5b542cd3503b595c31 Parents: 678ecb8 Author: acton393 <[email protected]> Authored: Wed Jan 17 11:12:45 2018 +0800 Committer: acton393 <[email protected]> Committed: Wed Jan 17 11:12:45 2018 +0800 ---------------------------------------------------------------------- WeexSDK.podspec | 2 +- .../WeexSDK/Sources/Bridge/WXBridgeContext.m | 10 ++++-- ios/sdk/WeexSDK/Sources/Bridge/WXJSCoreBridge.h | 2 +- ios/sdk/WeexSDK/Sources/Bridge/WXJSCoreBridge.m | 11 ++++++- .../WeexSDK/Sources/Manager/WXBridgeManager.h | 2 -- .../WeexSDK/Sources/Manager/WXBridgeManager.m | 2 +- ios/sdk/WeexSDK/Sources/Manager/WXSDKManager.h | 6 ++++ ios/sdk/WeexSDK/Sources/Manager/WXSDKManager.m | 12 ++++++-- ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m | 32 ++++++++++++++++++-- .../Sources/Model/WXSDKInstance_private.h | 1 + 10 files changed, 67 insertions(+), 13 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/46910ade/WeexSDK.podspec ---------------------------------------------------------------------- diff --git a/WeexSDK.podspec b/WeexSDK.podspec index abadcdc..3e33b86 100644 --- a/WeexSDK.podspec +++ b/WeexSDK.podspec @@ -28,7 +28,7 @@ Pod::Spec.new do |s| s.ios.deployment_target = '7.0' s.source = { :path => '.' } s.source_files = 'ios/sdk/WeexSDK/Sources/**/*.{h,m,mm,c}' - s.resources = 'pre-build/native-bundle-main.js', 'pre-build/weex-rax-api.js', 'ios/sdk/WeexSDK/Resources/[email protected]' + s.resources = 'pre-build/native-bundle-main.js','pre-build/weex-main-jsfm.js', 'pre-build/weex-rax-api.js', 'ios/sdk/WeexSDK/Resources/[email protected]' s.user_target_xcconfig = { 'FRAMEWORK_SEARCH_PATHS' => "'$(PODS_ROOT)/WeexSDK'" } s.requires_arc = true http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/46910ade/ios/sdk/WeexSDK/Sources/Bridge/WXBridgeContext.m ---------------------------------------------------------------------- diff --git a/ios/sdk/WeexSDK/Sources/Bridge/WXBridgeContext.m b/ios/sdk/WeexSDK/Sources/Bridge/WXBridgeContext.m index 2aa3d64..a6b1fc8 100644 --- a/ios/sdk/WeexSDK/Sources/Bridge/WXBridgeContext.m +++ b/ios/sdk/WeexSDK/Sources/Bridge/WXBridgeContext.m @@ -450,9 +450,11 @@ _Pragma("clang diagnostic pop") \ shoudMultiContext = [[configCenter configForKey:@"iOS_weex_ext_config.createInstanceUsingMutliContext" defaultValue:@(NO) isDefault:NULL] boolValue]; } __weak typeof(self) weakSelf = self; - JSContext *globalContex = ([(JSContext*)weakSelf.jsBridge valueForKey:@"jsContext"]); + JSContext *globalContex = nil; NSString * bundleType = nil; + if (shoudMultiContext) { + globalContex = ([(JSContext*)weakSelf.jsBridge valueForKey:@"jsContext"]); bundleType = [self _pareJSBundleType:instanceIdString jsBundleString:jsBundleString]; // bundleType can be Vue, Rax and the new framework. } if (bundleType&&shoudMultiContext) { @@ -491,8 +493,12 @@ _Pragma("clang diagnostic pop") \ WXLogError(@"weex-rax-api can not found"); } } + if ([NSURL URLWithString:sdkInstance.pageName]) { + [sdkInstance.instanceJavaScriptContext evaluateScript:jsBundleString withSourceURL:[NSURL URLWithString:sdkInstance.pageName]]; + } else { + [sdkInstance.instanceJavaScriptContext evaluateScript:jsBundleString]; + } - [sdkInstance.instanceJavaScriptContext evaluateScript:jsBundleString]; }]; } else { if (data){ http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/46910ade/ios/sdk/WeexSDK/Sources/Bridge/WXJSCoreBridge.h ---------------------------------------------------------------------- diff --git a/ios/sdk/WeexSDK/Sources/Bridge/WXJSCoreBridge.h b/ios/sdk/WeexSDK/Sources/Bridge/WXJSCoreBridge.h index 42e3e1b..6472ea7 100644 --- a/ios/sdk/WeexSDK/Sources/Bridge/WXJSCoreBridge.h +++ b/ios/sdk/WeexSDK/Sources/Bridge/WXJSCoreBridge.h @@ -20,5 +20,5 @@ #import "WXBridgeProtocol.h" @interface WXJSCoreBridge : NSObject <WXBridgeProtocol> - +@property (nonatomic,assign)BOOL multiContext; @end http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/46910ade/ios/sdk/WeexSDK/Sources/Bridge/WXJSCoreBridge.m ---------------------------------------------------------------------- diff --git a/ios/sdk/WeexSDK/Sources/Bridge/WXJSCoreBridge.m b/ios/sdk/WeexSDK/Sources/Bridge/WXJSCoreBridge.m index cc0da9e..6afde5d 100644 --- a/ios/sdk/WeexSDK/Sources/Bridge/WXJSCoreBridge.m +++ b/ios/sdk/WeexSDK/Sources/Bridge/WXJSCoreBridge.m @@ -64,6 +64,7 @@ _callbacks = [NSMutableDictionary new]; _intervalTimerId = 0; _intervaltimers = [NSMutableDictionary new]; + _multiContext = NO; __weak typeof(self) weakSelf = self; @@ -102,13 +103,21 @@ return self; } +- (void)dealloc { + NSLog(@"%s", __PRETTY_FUNCTION__); +} + #pragma mark - WXBridgeProtocol - (void)executeJSFramework:(NSString *)frameworkScript { WXAssertParam(frameworkScript); if (WX_SYS_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.0")) { - [_jsContext evaluateScript:frameworkScript withSourceURL:[NSURL URLWithString:@"native-bundle-main.js"]]; + NSString * fileName = @"native-bundle-main.js"; + if ([WXSDKManager sharedInstance].multiContext) { + fileName = @"weex-main-jsfm.js"; + } + [_jsContext evaluateScript:frameworkScript withSourceURL:[NSURL URLWithString:fileName]]; }else{ [_jsContext evaluateScript:frameworkScript]; } http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/46910ade/ios/sdk/WeexSDK/Sources/Manager/WXBridgeManager.h ---------------------------------------------------------------------- diff --git a/ios/sdk/WeexSDK/Sources/Manager/WXBridgeManager.h b/ios/sdk/WeexSDK/Sources/Manager/WXBridgeManager.h index 6cf554d..77fec46 100644 --- a/ios/sdk/WeexSDK/Sources/Manager/WXBridgeManager.h +++ b/ios/sdk/WeexSDK/Sources/Manager/WXBridgeManager.h @@ -31,8 +31,6 @@ extern void WXPerformBlockOnBridgeThread(void (^block)(void)); **/ @property (nonatomic, weak, readonly) WXSDKInstance *topInstance; -+ (instancetype)sharedManager; - /** * Create Instance Method * @param instance : instance id http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/46910ade/ios/sdk/WeexSDK/Sources/Manager/WXBridgeManager.m ---------------------------------------------------------------------- diff --git a/ios/sdk/WeexSDK/Sources/Manager/WXBridgeManager.m b/ios/sdk/WeexSDK/Sources/Manager/WXBridgeManager.m index 896bed7..d91f972 100644 --- a/ios/sdk/WeexSDK/Sources/Manager/WXBridgeManager.m +++ b/ios/sdk/WeexSDK/Sources/Manager/WXBridgeManager.m @@ -74,7 +74,7 @@ static NSThread *WXBridgeThread; - (void)dealloc { - + NSLog(@"%s",__PRETTY_FUNCTION__); } #pragma mark Thread Management http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/46910ade/ios/sdk/WeexSDK/Sources/Manager/WXSDKManager.h ---------------------------------------------------------------------- diff --git a/ios/sdk/WeexSDK/Sources/Manager/WXSDKManager.h b/ios/sdk/WeexSDK/Sources/Manager/WXSDKManager.h index b0e705f..f272347 100644 --- a/ios/sdk/WeexSDK/Sources/Manager/WXSDKManager.h +++ b/ios/sdk/WeexSDK/Sources/Manager/WXSDKManager.h @@ -25,6 +25,12 @@ @interface WXSDKManager : NSObject +@property (nonatomic, assign) BOOL multiContext; + +/** + *@abstract Returns sdk manager + */ ++ (WXSDKManager *)sharedInstance; /** * @abstract Returns bridge manager **/ http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/46910ade/ios/sdk/WeexSDK/Sources/Manager/WXSDKManager.m ---------------------------------------------------------------------- diff --git a/ios/sdk/WeexSDK/Sources/Manager/WXSDKManager.m b/ios/sdk/WeexSDK/Sources/Manager/WXSDKManager.m index 53987c0..797f4b7 100644 --- a/ios/sdk/WeexSDK/Sources/Manager/WXSDKManager.m +++ b/ios/sdk/WeexSDK/Sources/Manager/WXSDKManager.m @@ -44,11 +44,19 @@ static WXSDKManager *_sharedInstance = nil; return _sharedInstance; } +- (instancetype)init +{ + if (self = [super init]){ + + } + return self; +} + + (WXBridgeManager *)bridgeMgr { WXBridgeManager *bridgeMgr = [self sharedInstance].bridgeMgr; if (!bridgeMgr) { - bridgeMgr = [WXBridgeManager sharedManager]; + bridgeMgr = [[WXBridgeManager alloc] init]; [self sharedInstance].bridgeMgr = bridgeMgr; } return bridgeMgr; @@ -77,7 +85,7 @@ static WXSDKManager *_sharedInstance = nil; WXSDKInstance *instance = [[self sharedInstance].instanceDict objectForKey:instanceID]; [instance destroyInstance]; } - + [[self sharedInstance].bridgeMgr unload]; [self sharedInstance].bridgeMgr = nil; } http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/46910ade/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m ---------------------------------------------------------------------- diff --git a/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m b/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m index f0e5ef7..cc52d17 100644 --- a/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m +++ b/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m @@ -213,8 +213,10 @@ typedef enum : NSUInteger { // ensure default modules/components/handlers are ready before create instance [WXSDKEngine registerDefaults]; [[NSNotificationCenter defaultCenter] postNotificationName:WX_SDKINSTANCE_WILL_RENDER object:self]; - - [self _handleConfigCenter]; + _mainBundleString = mainBundleString; + if ([self _handleConfigCenter]) { + return; + } [WXTracingManager startTracingWithInstanceId:self.instanceId ref:nil className:nil name:WXTExecJS phase:WXTracingBegin functionName:@"renderWithMainBundleString" options:@{@"threadName":WXTMainThread}]; [[WXSDKManager bridgeMgr] createInstance:self.instanceId template:mainBundleString options:dictionary data:_jsData]; @@ -223,7 +225,7 @@ typedef enum : NSUInteger { WX_MONITOR_PERF_SET(WXPTBundleSize, [mainBundleString lengthOfBytesUsingEncoding:NSUTF8StringEncoding], self); } -- (void)_handleConfigCenter +- (BOOL)_handleConfigCenter { id configCenter = [WXSDKEngine handlerForProtocol:@protocol(WXConfigCenterProtocol)]; if ([configCenter respondsToSelector:@selector(configForKey:defaultValue:isDefault:)]) { @@ -231,7 +233,30 @@ typedef enum : NSUInteger { [WXTextComponent setRenderUsingCoreText:useCoreText]; BOOL useThreadSafeLock = [[configCenter configForKey:@"iOS_weex_ext_config.useThreadSafeLock" defaultValue:@NO isDefault:NULL] boolValue]; [WXUtility setThreadSafeCollectionUsingLock:useThreadSafeLock]; + BOOL shoudMultiContext = NO; + if ([configCenter respondsToSelector:@selector(configForKey:defaultValue:isDefault:)]) { + shoudMultiContext = [[configCenter configForKey:@"iOS_weex_ext_config.createInstanceUsingMutliContext" defaultValue:@(NO) isDefault:NULL] boolValue]; + } + if(shoudMultiContext && ![WXSDKManager sharedInstance].multiContext) { + [WXSDKManager sharedInstance].multiContext = YES; + NSString *filePath = [[NSBundle bundleForClass:[self class]] pathForResource:@"weex-main-jsfm" ofType:@"js"]; + NSString *script = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil]; + [WXSDKEngine restartWithScript:script]; + [[NSNotificationCenter defaultCenter] postNotificationName:@"WXSDKENFINE_RESTARTED" object:nil]; + return YES; + } + if (!shoudMultiContext && [WXSDKManager sharedInstance].multiContext) { + [WXSDKManager sharedInstance].multiContext = NO; + [WXSDKEngine restart]; + [[NSNotificationCenter defaultCenter] postNotificationName:@"WXSDKENFINE_RESTARTED" object:nil]; + return YES; + } } + return NO; +} + +- (void)renderWithMainBundleString:(NSNotification*)notification { + [self _renderWithMainBundleString:_mainBundleString]; } - (void)_renderWithRequest:(WXResourceRequest *)request options:(NSDictionary *)options data:(id)data; @@ -607,6 +632,7 @@ typedef enum : NSUInteger { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillResignActive:) name:UIApplicationWillResignActiveNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidBecomeActive:) name:UIApplicationDidBecomeActiveNotification object:nil]; [self addObserver:self forKeyPath:@"state" options:NSKeyValueObservingOptionNew context:nil]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(renderWithMainBundleString:) name:@"WXSDKENFINE_RESTARTED" object:nil]; } - (void)removeObservers http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/46910ade/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance_private.h ---------------------------------------------------------------------- diff --git a/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance_private.h b/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance_private.h index 09d308e..a62ad33 100644 --- a/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance_private.h +++ b/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance_private.h @@ -31,6 +31,7 @@ @property (nonatomic, strong) NSMutableDictionary *naviBarStyles; @property (nonatomic, strong) NSMutableDictionary *styleConfigs; @property (nonatomic, strong) NSMutableDictionary *attrConfigs; +@property (nonatomic, strong) NSString *mainBundleString; @property (nonatomic, strong) JSContext *instanceJavaScriptContext; // sandbox javaScript context @property (nonatomic, readonly, strong) WXComponentManager *componentManager;
