React Native - 无法执行 JS 调用:__fbBatchedBridge 未定义 [英] React Native - Unable to execute JS call: __fbBatchedBridge is undefined

查看:58
本文介绍了React Native - 无法执行 JS 调用:__fbBatchedBridge 未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在关注本教程

但不久之后屏幕消失并显示:

错误文本为:

无法执行JS调用:__fbBatchedBridge未定义

它在不到 24 小时前还在工作,所以不确定发生了什么.Fwiw,我完全删除了项目并重新开始.

这个答案(无法执行JS调用:__fbBatchedBridge未定义) 建议检查它是否通过网络获取代码.这似乎不是问题.

App Delegate 中的完整代码如下:

/*** 版权所有 (c) 2015 年至今,Facebook, Inc.* 版权所有.** 这个源代码是在 BSD 风格的许可下获得许可的* 此源代码树的根目录中的 LICENSE 文件.额外补助* 的专利权可以在同一目录下的PATENTS 文件中找到.*/#import "AppDelegate.h"#import "RCTRootView.h"@implementation AppDelegate- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{NSURL *jsCodeLocation;/*** 加载 JavaScript 代码 - 取消注释您想要的代码.** 选项1* 从开发服务器加载.从存储库根目录启动服务器:** $ npm start** 要在设备上运行,请将localhost"更改为您计算机的 IP 地址*(您可以通过在终端中输入 `ifconfig` 并选择* `en0:` 下的 `inet` 值)并确保您的计算机和 iOS 设备是* 在同一个 Wi-Fi 网络上.*/jsCodeLocation = [NSURL URLWithString:@"http://localhost:8081/index.ios.bundle?platform=ios&dev=true"];/*** 选项 2* 从磁盘上的预捆绑文件加载.静态包是自动的* 由Bundle React Native code and images"构建步骤生成* 在实际设备上运行项目或在设备上运行项目*发布"构建配置中的模拟器.*///jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation模块名称:@"PropertyFinder"初始属性:无启动选项:启动选项];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];返回是;}@结尾

解决方案

重新启动 metro bundler 帮助了我!

I've been following this tutorial https://www.raywenderlich.com/126063/react-native-tutorial

and decided to start from scratch after experiencing problems.

I ran react-native init PropertyFinder and opened up the project in Xcode. When I compile and run it, it opens in the Simulator as expected showing:

but shortly afterwards the screen fades and shows this:

The error text is:

Unable to execute JS call: __fbBatchedBridge is undefined

It was working less than 24 hours ago so not sure what's going on. Fwiw, I completely deleted the project and started again.

This answer (Unable to execute JS call: __fbBatchedBridge is undefined) suggests checking it's fetching the code over the wire. It is so that doesn't seem to be the issue.

The full code in the App Delegate is as follows:

/**
 * Copyright (c) 2015-present, Facebook, Inc.
 * All rights reserved.
 *
 * This source code is licensed under the BSD-style license found in the
 * LICENSE file in the root directory of this source tree. An additional grant
 * of patent rights can be found in the PATENTS file in the same directory.
 */

#import "AppDelegate.h"

#import "RCTRootView.h"

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  NSURL *jsCodeLocation;

  /**
   * Loading JavaScript code - uncomment the one you want.
   *
   * OPTION 1
   * Load from development server. Start the server from the repository root:
   *
   * $ npm start
   *
   * To run on device, change `localhost` to the IP address of your computer
   * (you can get this by typing `ifconfig` into the terminal and selecting the
   * `inet` value under `en0:`) and make sure your computer and iOS device are
   * on the same Wi-Fi network.
   */

  jsCodeLocation = [NSURL URLWithString:@"http://localhost:8081/index.ios.bundle?platform=ios&dev=true"];

  /**
   * OPTION 2
   * Load from pre-bundled file on disk. The static bundle is automatically
   * generated by the "Bundle React Native code and images" build step when
   * running the project on an actual device or running the project on the
   * simulator in the "Release" build configuration.
   */

//   jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];

  RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
                                                      moduleName:@"PropertyFinder"
                                               initialProperties:nil
                                                   launchOptions:launchOptions];
  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 YES;
}

@end

解决方案

Restarting the metro bundler helped me!

这篇关于React Native - 无法执行 JS 调用:__fbBatchedBridge 未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆