Dennis Dennis - 1 year ago 237
iOS Question

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. 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
on Xcode).

This works fine, even if (after startup) I disable WiFi and disconnect the phone from my 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)...

At startup I can see a green bar labeled something like "Connecting to 192.*" (which is propably the IP address of my mac). 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
section in
as suggested in the official documentation is not quite helpful since it's not possible having this generated code:

#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
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?


  • OSX 10.11.5

  • Xcode 7.3.1

  • React Native 0.3

  • npm 3.10.3

Answer Source

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. 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 script automatically runs bundle command for you and prepares assets as well as your Javascript code for being stored on the device.

To do so, simply click on the name of your project (in this case, it's Basic): enter image description here

then from the modal, choose Edit Scheme and change Build configuration from Debug to 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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download