react-native: Documentation missing instructions for running on device via static bundle

If anyone wants to improve on these instructions and add them to the docs, feel free, I can do it later if nobody else jumps on it - I just wanted to document it somewhere for now.

  • Open iOS/AppDelegate.m
  • Comment out jsCodeLocation = [NSURL URLWithString:@"http://localhost:8081/index.ios.bundle"];
  • Uncomment jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
  • Start up the packager with npm start and then run curl http://localhost:8081/index.ios.bundle -o main.jsbundle - if this fails (as it did on my machine) add the --ipv4 flag to the end of it.
  • In XCode, right click on your project directory and click Add Files to "Project Name Here" - choose the main.jsbundle file that you generated.

You can now run the app on a device (either via usb or TestFlight) without needing to have a server running.

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Reactions: 45
  • Comments: 35 (9 by maintainers)

Commits related to this issue

Most upvoted comments

Currently (react-native@0.43), the AppDelegate.m is different. We can follow steps bellow:

  1. Comment the original jsCodeLocation line and add the new one:

    /*jsCodeLocation = [[RCTBundleURLProvider sharedSettings] 
    jsBundleURLForBundleRoot:@"index.ios" fallbackResource:nil];*/
    jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
    
  2. Run react-native bundle --platform ios --dev false --entry-file index.ios.js --bundle-output main.jsbundle at root dir. And you will get two files: main.jsbundle and main.jsbundle.meta.

  3. Right click your project and select Add Files to "yourProject" in Xcode, select main.jsbundle you created with step 2.

2017-04-27 8 00 55

Then build the app and you can run it in your device.

I have a issue! Is possible to run my react native app on iPad with Xcode 8.3 without having the usb cable connected?

I’m doing this with a pre-existing swift codebase. Using let jsCodeLocation = NSBundle.mainBundle().URLForResource("main", withExtension: "jsbundle") inside AppDelegate.swift works

FYI. The instructions are “available” @ https://github.com/facebook/react-native/blob/master/Examples/SampleApp/iOS/AppDelegate.m#L31

But I def had to add the step:

  • In XCode, right click on your project directory and click Add Files to “Project Name Here”
  • choose the main.jsbundle file that you generated via curl command.