OGeek|极客世界-中国程序员成长平台

标题: ios - 在 iPhone 上运行 React Native 应用程序 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 13:54
标题: ios - 在 iPhone 上运行 React Native 应用程序

我正在尝试运行使用 react native (v0.3) 创建的应用程序,而根本没有连接到我的计算机。我已经将应用程序与 react-native bundle --dev false --entry-file index.ios.js --bundle-output ios/main.jsbundle --platform ios 捆绑在一起并在我的连接的 iPhone(在 Xcode 上也更改为 Release)。

即使(在启动后)我禁用 WiFi 并断开手机与我的 mac 的连接,这也可以正常工作。但是,如果我完全关闭应用程序并尝试再次启动它(没有连接 WiFi 或 USB)它会崩溃(它会显示应用程序屏幕并在几秒钟后崩溃)...

在启动时,我可以看到一个标有“连接到 192.*”的绿色条(这可能是我的 mac 的 IP 地址)。如何完全禁用连接?该连接对调试非常有用,但无法将应用展示给他人。

按照 official documentation 中的建议,在 AppDelegate.m 中取消注释 jsCodeLocation 部分不是很有帮助,因为不可能有这个生成的代码:

#import "AppDelegate.h"

#import "RCTBundleURLProvider.h"
#import "RCTRootView.h"

@implementation AppDelegate

- (BOOL)applicationUIApplication *)application didFinishLaunchingWithOptionsNSDictionary *)launchOptions
{
  NSURL *jsCodeLocation;

  jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot"index.ios" fallbackResource:nil];

  RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
                                                      moduleName"weather"
                                               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;
}

或者我只是在这里遗漏了什么?

版本:



Best Answer-推荐答案


其中一种可能的解决方案是在 Release 模式下运行您的应用程序,该模式将自动使用已编译的包而不是托管包。在开发模式下,bundle 不会被编译并存储在设备上,以使构建时间更短。当您将配置设置为 Release 时,react-native-xcode.sh 脚本会自动为您运行 bundle 命令并准备 Assets 以及用于存储在设备上的 Javascript 代码。

为此,只需单击您的项目名称(在本例中为 Basic): enter image description here

然后从模式中,选择 Edit Scheme 并将 Build configuration 从 Debug 更改为 Release。

请注意,您还可以创建一个新方案,以便同时使用调试和 Release模式。为此,只需从前面提到的模式中选择 New Scheme 而不是 Edit Scheme 并相应地应用相同的调整。

关于ios - 在 iPhone 上运行 React Native 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38660426/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4