[英]Running React Native App on iPhone
I'm trying to run an app created with react native (v0.3) without being connected to my computer at all. 我正在尝试运行使用react native(v0.3)创建的应用程序,而根本没有连接到我的计算机。 I've bundled the app with
react-native bundle --dev false --entry-file index.ios.js --bundle-output ios/main.jsbundle --platform ios
and run on my connected iPhone (also changed to Release
on Xcode). 我已经将应用程序与
react-native bundle --dev false --entry-file index.ios.js --bundle-output ios/main.jsbundle --platform ios
并在连接的iPhone上运行(也更改为Release
在Xcode上)。
This works fine, even if (after startup) I disable WiFi and disconnect the phone from my mac. 即使(在启动后)我禁用了WiFi并从Mac断开了手机的连接,它也能正常工作。 But if I close the app entirely and try to start it again (without WiFi or USB connected) it crashes (it shows the app screen and crashes after some seconds)...
但是,如果我完全关闭该应用程序并尝试再次启动它(未连接WiFi或USB),它将崩溃(显示应用程序屏幕并在几秒钟后崩溃)...
At startup I can see a green bar labeled something like "Connecting to 192.*" (which is propably the IP address of my mac). 在启动时,我会看到一个标有“正在连接到192。*”(可能是我的Mac的IP地址)之类的绿色条。 How can I disable the connection entirely?
如何完全禁用连接? The connection is quite useful to debug, but it's impossible to show the app to somebody.
该连接对于调试非常有用,但是无法向他人展示该应用程序。
Uncommenting the jsCodeLocation
section in AppDelegate.m
as suggested in the official documentation is not quite helpful since it's not possible having this generated code: 按照官方文档中的建议取消对
AppDelegate.m
的jsCodeLocation
部分的注释不是很有帮助,因为不可能生成以下代码:
#import "AppDelegate.h"
#import "RCTBundleURLProvider.h"
#import "RCTRootView.h"
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)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;
}
Or am I just missing something here? 还是我只是在这里想念东西?
Versions: 版本:
One of the possible solutions would be to run your app in the Release
mode which will automatically use the compiled bundle instead of the hosted one. 一种可能的解决方案是在
Release
模式下运行您的应用,该模式将自动使用编译后的捆绑包,而不是托管的捆绑包。 In the development mode, bundle is not compiled and stored on the device to make the build time smaller. 在开发模式下,不打包捆绑软件并将其存储在设备上,以缩短构建时间。 When you set the configuration to
Release
, the react-native-xcode.sh
script automatically runs bundle
command for you and prepares assets as well as your Javascript code for being stored on the device. 当您将配置设置为
Release
, react-native-xcode.sh
脚本会自动为您运行bundle
命令,并准备资产和Javascript代码以存储在设备上。
To do so, simply click on the name of your project (in this case, it's Basic): 为此,只需单击您的项目名称(在本例中为Basic):
then from the modal, choose Edit Scheme
and change Build configuration
from Debug to Release. 然后从模式中选择
Edit Scheme
并将Build configuration
从Debug更改为Release。
Note that you can also create a new scheme in order to have both Debug & Release modes available at once. 请注意,您还可以创建一个新方案,以同时具有调试和发布模式。 To do so, simply choose
New Scheme
from the previously mentioned modal instead of Edit Scheme
and apply the same tweaks accordingly. 为此,只需从前面提到的模式中选择“
New Scheme
”而不是“ Edit Scheme
并相应地应用相同的调整即可。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.