diff --git a/ios/sdk/WeexSDK/Sources/Bridge/WXCoreBridge.h b/ios/sdk/WeexSDK/Sources/Bridge/WXCoreBridge.h index 1b9223c4bc..f2face8d64 100644 --- a/ios/sdk/WeexSDK/Sources/Bridge/WXCoreBridge.h +++ b/ios/sdk/WeexSDK/Sources/Bridge/WXCoreBridge.h @@ -56,6 +56,9 @@ namespace WeexCore void CallNativeComponent(const char* pageId, const char* ref, const char *method, const char *arguments, int argumentsLength, const char *options, int optionsLength) override; +#if OS_IOS + std::unique_ptr RegisterPluginModule(const char *name, const char *class_name, const char *version) override; +#endif void SetTimeout(const char* callbackID, const char* time) override ; diff --git a/ios/sdk/WeexSDK/Sources/Bridge/WXCoreBridge.mm b/ios/sdk/WeexSDK/Sources/Bridge/WXCoreBridge.mm index ad7998053e..9010644928 100644 --- a/ios/sdk/WeexSDK/Sources/Bridge/WXCoreBridge.mm +++ b/ios/sdk/WeexSDK/Sources/Bridge/WXCoreBridge.mm @@ -33,6 +33,7 @@ #import "WXAppMonitorProtocol.h" #import "WXComponentMethod.h" #import "WXExceptionUtils.h" +#import "WXModuleFactory.h" #include "base/core_constants.h" #include "base/time_utils.h" @@ -177,7 +178,49 @@ static void MergeBorderWidthValues(NSMutableDictionary* dict, return result; } + +#if OS_IOS + std::unique_ptr IOSSide::RegisterPluginModule(const char *pcstr_name, const char *pcstr_class_name, const char *pcstr_version) { + ValueWithType *returnValue = new ValueWithType(); + memset(returnValue, 0, sizeof(ValueWithType)); + returnValue->type = ParamsType::VOID; + do { + if (!pcstr_class_name) { + break; + } + NSString *className = [NSString stringWithUTF8String:pcstr_class_name]; + Class clazz = NSClassFromString(className); + if (!clazz) { + break; + } + if (!pcstr_name) { + break; + } + NSString *name = [NSString stringWithUTF8String:pcstr_name]; + NSString *version = @"0"; + if (pcstr_version) { + version = [NSString stringWithUTF8String:pcstr_version]; + } + NSString *moduleName = [WXModuleFactory registerModule:name withClass:clazz]; + if (!moduleName.length) { + break; + } + NSDictionary *moduleInfo = [WXModuleFactory moduleMethodMapsWithName:moduleName]; + if (!moduleInfo || ![moduleInfo isKindOfClass:[NSDictionary class]]) { + break; + } + NSString *setting = [WXUtility JSONString:moduleInfo]; + if (setting.length > 0) { + returnValue->type = ParamsType::BYTEARRAYSTRING; + const char *pcstr_utf8 = [setting UTF8String]; + returnValue->value.byteArray = generator_bytes_array(pcstr_utf8, setting.length); + } + } while (0); + + return std::unique_ptr(returnValue); + } +#endif std::unique_ptr IOSSide::CallNativeModule(const char *page_id, const char *module, const char *method, const char *args, int args_length, const char *options, int options_length) { ValueWithType *returnValue = new ValueWithType(); diff --git a/ios/sdk/WeexSDK/Sources/Manager/WXBridgeManager.m b/ios/sdk/WeexSDK/Sources/Manager/WXBridgeManager.m index 1f531b1aca..2954a69a41 100644 --- a/ios/sdk/WeexSDK/Sources/Manager/WXBridgeManager.m +++ b/ios/sdk/WeexSDK/Sources/Manager/WXBridgeManager.m @@ -491,8 +491,9 @@ - (void)callBack:(NSString *)instanceId funcId:(NSString *)funcId params:(id)par if (instance.wlasmRender) { id dataRenderHandler = [WXHandlerFactory handlerForProtocol:@protocol(WXDataRenderHandler)]; if (dataRenderHandler) { + id strongArgs = params ? [params copy]:@"\"{}\""; WXPerformBlockOnComponentThread(^{ - [dataRenderHandler invokeCallBack:instanceId function:funcId args:params ? [params copy]:@"\"{}\"" keepAlive:keepAlive]; + [dataRenderHandler invokeCallBack:instanceId function:funcId args:strongArgs keepAlive:keepAlive]; }); } else { diff --git a/weex_core/Source/core/bridge/eagle_bridge.cpp b/weex_core/Source/core/bridge/eagle_bridge.cpp index 8fae64c896..d30f78f0dc 100644 --- a/weex_core/Source/core/bridge/eagle_bridge.cpp +++ b/weex_core/Source/core/bridge/eagle_bridge.cpp @@ -151,7 +151,14 @@ namespace WeexCore { ->platform_side() ->CallNativeModule(page_id, module, method, arguments, arguments_length, options, options_length); } - +#if OS_IOS + std::unique_ptr EagleBridge::WeexCoreHandler::RegisterPluginModule(const std::string &name, const std::string &class_name, const std::string &version) { + return WeexCoreManager::Instance() + ->getPlatformBridge() + ->platform_side() + ->RegisterPluginModule(name.c_str(), class_name.c_str(), version.c_str()); + } +#endif void EagleBridge::WeexCoreHandler::CallNativeComponent(const char* page_id, const char* module, const char* method,const char* arguments, int arguments_length, const char* options, int options_length) { WeexCoreManager::Instance() ->getPlatformBridge() diff --git a/weex_core/Source/core/bridge/eagle_bridge.h b/weex_core/Source/core/bridge/eagle_bridge.h index a4829f50ae..2f98be8901 100644 --- a/weex_core/Source/core/bridge/eagle_bridge.h +++ b/weex_core/Source/core/bridge/eagle_bridge.h @@ -105,6 +105,9 @@ namespace WeexCore { const char *func, std::vector ¶ms); void PostTaskToMsgLoop(const weex::base::Closure& closure); +#if OS_IOS + std::unique_ptr RegisterPluginModule(const std::string &name, const std::string &class_name, const std::string &version); +#endif }; class DataRenderHandler { diff --git a/weex_core/Source/core/bridge/platform/core_side_in_platform.cpp b/weex_core/Source/core/bridge/platform/core_side_in_platform.cpp index 833b3a06b0..674409cd88 100644 --- a/weex_core/Source/core/bridge/platform/core_side_in_platform.cpp +++ b/weex_core/Source/core/bridge/platform/core_side_in_platform.cpp @@ -320,8 +320,8 @@ int CoreSideInPlatform::RefreshInstance( std::string init_data = weex::base::to_utf8(params[1]->value.string->content, params[1]->value.string->length); - - if (EagleBridge::GetInstance()->data_render_handler()->RefreshPage(instanceId, init_data)) { + auto handler = EagleBridge::GetInstance()->data_render_handler(); + if (handler && handler->RefreshPage(instanceId, init_data)) { return true; } return ExecJS(instanceId, nameSpace, func, params); @@ -443,7 +443,13 @@ int CoreSideInPlatform::CreateInstance(const char *instanceId, const char *func, extendsApi.c_str(),params); }; if (strcmp(render_strategy, "DATA_RENDER") == 0) { - EagleBridge::GetInstance()->data_render_handler()->CreatePage(script, instanceId, render_strategy, initData, exec_js); + auto handler = EagleBridge::GetInstance()->data_render_handler(); + if(handler){ + handler->CreatePage(script, instanceId, render_strategy, initData, exec_js); + } + else{ + LOGE("DATA_RENDER mode should not be used if there is no data_render_handler"); + } return true; } else if (strcmp(render_strategy, "DATA_RENDER_BINARY") == 0) { @@ -475,7 +481,14 @@ int CoreSideInPlatform::CreateInstance(const char *instanceId, const char *func, }; option = json11::Json(new_option).dump(); } - EagleBridge::GetInstance()->data_render_handler()->CreatePage(script, static_cast(script_length), instanceId, option, env_str, initData, exec_js); + + auto handler = EagleBridge::GetInstance()->data_render_handler(); + if(handler){ + handler->CreatePage(script, static_cast(script_length), instanceId, option, env_str, initData, exec_js); + } + else{ + LOGE("DATA_RENDER_BINARY mode should not be used if there is no data_render_handler"); + } return true; } } diff --git a/weex_core/Source/core/bridge/platform_bridge.h b/weex_core/Source/core/bridge/platform_bridge.h index 38602bb291..c5954c73f0 100644 --- a/weex_core/Source/core/bridge/platform_bridge.h +++ b/weex_core/Source/core/bridge/platform_bridge.h @@ -169,6 +169,9 @@ class PlatformBridge { const char* method, const char* arguments, int arguments_length, const char* options, int options_length) = 0; +#if OS_IOS + virtual std::unique_ptr RegisterPluginModule(const char *name, const char *class_name, const char *version) = 0; +#endif virtual void SetTimeout(const char* callback_id, const char* time) = 0; virtual void NativeLog(const char* str_array) = 0; virtual int UpdateFinish(const char* page_id, const char* task, int taskLen,