ios - 我可以实例化两个 RCTBridge 实例吗?
问题描述
出于某种原因,当我尝试实例化一个额外的RCTBridge
实例时,只有一个被启动(首先创建的那个)。这是我的 AppDelegate 中的代码:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Setup sync worker
self.syncThreadBridge = [[RCTBridge alloc] initWithDelegate:[SyncWorkerBridgeDelegate new] launchOptions:nil];
// React Native root view
RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
moduleName:@"Main_app"
initialProperties:nil];
rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
UIViewController *rootViewController = [UIViewController new];
rootViewController.view = rootView;
self.window.rootViewController = rootViewController;
[self.window makeKeyAndVisible];
// Return
return YES;
}
使用此代码,仅启动同步线程桥,而不启动应用程序的主桥(但同步线程桥成功初始化并向 Reactotron 发送消息)。
如果我将同步线程桥初始化移到主应用桥初始化下方,则主应用被初始化,呈现给用户,主应用向 Reactotron 发送消息。但是,同步线程桥不会启动,也不会连接到 Reactotron。
我的方法基于来自https://github.com/joltup/react-native-threads的代码——那里的示例代码似乎不适用于我使用的 React Native 0.63。
那么创建多个 JS 运行时的选项被删除了吗?
解决方案
实际上,我只是在一个全新的 React Native 0.63.4 应用程序上尝试过这个,它可以工作:https ://github.com/backmeupplz/react-native-ios-threading-example
推荐阅读
- apache-spark - 生成 2 个 Pyspark 数据帧之间的不匹配列报告
- r - 在 ggplot2 3.1.1 中工作的注释在 3.2.1 中失败。怎么修?
- macos - 如何让我的 Mac 在 usr/local/bin 之前搜索 usr/local/opt 以便它使用 brew 安装的包而不是系统包?
- javascript - JavaScript - 通过 cmd 提问并存储对变量的响应。将此代码添加到现有程序中
- swift - 无法将“Double”类型的值分配给“String”类型?
- python - 组 2 列并基于组值取基于特定值的组
- php - 来自 laravel 的注册视图不显示和识别来自我的控制器 Laravel 6.0 的变量
- scala - 如何对嵌套案例对象使用播放格式序列化/反序列化宏
- javascript - 接收和发送表单数据
- security - 如果跨组织启用 chrome 开发工具,是否存在任何潜在的安全问题?