Sno*_*ash 12 xcode react-native
我一直在关注本教程https://www.raywenderlich.com/126063/react-native-tutorial
并在遇到问题后决定从头开始。
我react-native init PropertyFinder在 Xcode 中运行并打开了该项目。当我编译并运行它时,它按预期在模拟器中打开,显示:
但不久之后屏幕消失并显示:
错误文本是:
Unable to execute JS call: __fbBatchedBridge is undefined
Run Code Online (Sandbox Code Playgroud)
它在不到 24 小时前还在工作,所以不确定发生了什么。Fwiw,我完全删除了该项目并重新开始。
这个答案(无法执行 JS 调用:__fbBatchedBridge 未定义)建议检查它是否通过网络获取代码。这似乎不是问题。
App Delegate中的完整代码如下:
/**
* 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
Run Code Online (Sandbox Code Playgroud)
这很可能是由于应用程序尝试从捆绑包而不是打包程序加载。您只能通过打包器运行模拟器。进入AppDelegate.m文件并确保该行未被注释
jsCodeLocation = [NSURL URLWithString:@"http://localhost:8081/index.ios.bundle?platform=ios&dev=true"];
Run Code Online (Sandbox Code Playgroud)
这行被注释了
// jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
Run Code Online (Sandbox Code Playgroud)
该应用程序仍会显示为正在加载,因为这只是加载屏幕,这是反应前的。一旦 React 启动,它就会失败。
| 归档时间: |
|
| 查看次数: |
8175 次 |
| 最近记录: |