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 runcurl 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 themain.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)
Currently (
react-native@0.43
), theAppDelegate.m
is different. We can follow steps bellow:Comment the original
jsCodeLocation
line and add the new one: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
andmain.jsbundle.meta
.Right click your project and select
Add Files to "yourProject"
in Xcode, selectmain.jsbundle
you created with step 2.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")
insideAppDelegate.swift
worksFYI. 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:
main.jsbundle
file that you generated via curl command.