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 startand then runcurl http://localhost:8081/index.ios.bundle -o main.jsbundle- if this fails (as it did on my machine) add the--ipv4flag to the end of it. - In XCode, right click on your project directory and click
Add Files to "Project Name Here"- choose themain.jsbundlefile 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.mis different. We can follow steps bellow:Comment the original
jsCodeLocationline and add the new one:Run
react-native bundle --platform ios --dev false --entry-file index.ios.js --bundle-output main.jsbundleat root dir. And you will get two files:main.jsbundleandmain.jsbundle.meta.Right click your project and select
Add Files to "yourProject"in Xcode, selectmain.jsbundleyou 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.swiftworksFYI. 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.jsbundlefile that you generated via curl command.