Xcode React Native-无法执行JS调用:\ fBatchedBridge未定义

Xcode React Native-无法执行JS调用:\ fBatchedBridge未定义,xcode,react-native,Xcode,React Native,我一直在学习这个教程 遇到问题后,决定从头开始 我运行了react native init PropertyFinder,并在Xcode中打开了该项目。当我编译并运行它时,它会按预期在模拟器中打开,显示: 但不久之后,屏幕淡出并显示以下内容: 错误文本为: Unable to execute JS call: __fbBatchedBridge is undefined 不到24小时前它还在工作,所以不知道发生了什么。Fwiw,我完全删除了该项目并重新开始 这个答案()建议检查它是否通过线

我一直在学习这个教程

遇到问题后,决定从头开始

我运行了react native init PropertyFinder,并在Xcode中打开了该项目。当我编译并运行它时,它会按预期在模拟器中打开,显示:

但不久之后,屏幕淡出并显示以下内容:

错误文本为:

Unable to execute JS call: __fbBatchedBridge is undefined
不到24小时前它还在工作,所以不知道发生了什么。Fwiw,我完全删除了该项目并重新开始

这个答案()建议检查它是否通过线路获取代码。这似乎不是问题所在

应用程序委托中的完整代码如下所示:

/**
 * 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

这很可能是因为应用程序试图从捆绑包而不是打包机加载。您只能通过打包机运行模拟器。进入AppDelegate.m文件并确保此行未注释

jsCodeLocation = [NSURL URLWithString:@"http://localhost:8081/index.ios.bundle?platform=ios&dev=true"];
// jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
这一行被注释了

// jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
应用程序仍将显示为加载,因为这只是加载屏幕,这是预反应。一旦反应开始,它就会失败


.

您可以尝试此更改

jsCodeLocation = [NSURL URLWithString:@"http://localhost:8081/?platform=ios&dev=false"];

在文件AppDelegate.m中。
要点是“index.ios.bundle”,有时是“index.ios”,然后在后面添加“.bundle”。我用这个解决了这个问题。

重新启动地铁捆绑机帮助了我

您是从捆包还是从包装机装货?它将位于AppDelegate.m文件中。您无法从捆绑包运行模拟器。我将按照说明启动.xcodeproj文件。很明显,在初始页面加载时有些东西在工作。不,我得到的代码使用的是NSURL。e、 g.在应用程序委托中可以看到这一点:
jsCodeLocation=[NSURL URLWithString:@”http://localhost:8081/index.ios.bundle?platform=ios&dev=true"];您确定打包机正在运行吗?您是否看到正在发生的转换?我如何知道打包机正在运行?还是发生了转变?我在你发布的帖子中搜索了这两个,但没有找到任何东西。我假设你的服务器正在运行?在项目目录中运行
react native start
。它在
localhost:8081
上启动一个服务器,该服务器应该为您的项目资源提供服务。啊-我理解。是的,我通过Xcode启动了该应用程序,并生成了一个启动服务器的终端。我不知道为什么,但这个问题已经解决了。奇怪的是,我没有做任何改变。