You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Documentation missing instructions for running on device via static bundle #240
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"];
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.
Worth noting, (at least unless I am missing something) if you go down this path, you will have to run the curl step, every time. If you want to see your changes.
I dug around and got all the way to the last step before I had to start sifting through issues, thanks for outlining the steps, now it can actually find the bundle file 👍
Does this mean that we can host the whole bundle on a remote nodejs server, and always load the bundle (the react part) over http from the client? This would be great to deploy new features without having to rebuild the ios app. Is this realistic or doesn't Apple allow dynamic app functionality like that?
It'd be great to verify whether a remote hosted bundle would work or not. It seems like it should work, you ship one version with the app, and save/update the local bundle based on some remote bundle. Updates to any wrapped native modules would still require an app store update though.
I get the same error when I run npm start. Not sure what I'm doing wrong in the app.m file? Where do I change my IP address? run curl? I can't seem to get the packager running.
@satya164 is right, we now have a special script integrated into the build process that does this for you (see #3545 (comment)). @kainliu the problem with your command line is that it won't work for images, i.e. if you are using require('./image-name.png') inside your bundle, it won't be packed into the app.
I'm doing this with a pre-existing swift codebase. Using let jsCodeLocation = NSBundle.mainBundle().URLForResource("main", withExtension: "jsbundle") inside AppDelegate.swift works
HI @brentvatne!
I did Comment out jsCodeLocation = [NSURL URLWithString:@"http://localhost:8081/index.ios.bundle"];
Uncomment jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
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.
Right click your project and select Add Files to "yourProject" in Xcode, select main.jsbundle you created with step 2.
Then build the app and you can run it in your device.
Reacted by grassmoon, snvfk1n, kevin, Julien Saito and Milad
@creeperyang How do I keep it updated everytime. Once the bundle is created, it never changes. Even after making small changes in index.ios.js, it doesn't get reflected in main.jsbundle.
Activity
stolemotion commentedon Mar 26, 2015
Thanks man, I was wondering why it wouldn't run. For anyone else seeking an answer to "Could not connect to development server" look here.
freshteapot commentedon Mar 27, 2015
Worth noting, (at least unless I am missing something) if you go down this path, you will have to run the curl step, every time. If you want to see your changes.
magus commentedon Mar 27, 2015
I dug around and got all the way to the last step before I had to start sifting through issues, thanks for outlining the steps, now it can actually find the bundle file 👍
drkibitz commentedon Mar 27, 2015
Just noting here, nothing is requiring you to run a node server, could also just serve a static bundle. Could also make the URL a debug app setting.
AgtLucas commentedon Mar 27, 2015
Thanks!
jonaswindey commentedon Mar 28, 2015
Does this mean that we can host the whole bundle on a remote nodejs server, and always load the bundle (the react part) over http from the client? This would be great to deploy new features without having to rebuild the ios app. Is this realistic or doesn't Apple allow dynamic app functionality like that?
AgtLucas commentedon Mar 28, 2015
@jonaswindey
As far as I know, this is impossible, Apple doesn't allow this.
jonaswindey commentedon Mar 28, 2015
https://www.meteor.com/blog/2014/10/02/Apple-hot-code-push-mobile
This could be great if we could update all our React logic dynamically without the clients having to be updated.
magus commentedon Mar 28, 2015
It'd be great to verify whether a remote hosted bundle would work or not. It seems like it should work, you ship one version with the app, and save/update the local bundle based on some remote bundle. Updates to any wrapped native modules would still require an app store update though.
jordpo commentedon Mar 29, 2015
Awesome- thank you!
bradoyler commentedon Mar 29, 2015
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:
main.jsbundlefile that you generated via curl command.erinjerri commentedon Apr 6, 2015
I get the same error when I run npm start. Not sure what I'm doing wrong in the app.m file? Where do I change my IP address? run curl? I can't seem to get the packager running.
erinjerri commentedon Apr 6, 2015
Nevermind, I realized I didn't add in the main.jsbundle
referenced here: http://stackoverflow.com/questions/29374410/how-to-build-react-native-app-for-iphone/29468098#29468098
10 remaining items
frantic commentedon Feb 5, 2016
@satya164 is right, we now have a special script integrated into the build process that does this for you (see #3545 (comment)). @kainliu the problem with your command line is that it won't work for images, i.e. if you are using
require('./image-name.png')inside your bundle, it won't be packed into the app.lkaihua commentedon Feb 11, 2016
@frantic @satya164 The
shscript works quite well and thanks for pointing out the shortcoming.joshuapinter commentedon Feb 22, 2016
@satya164 👍
mihir0x69 commentedon Feb 25, 2016
@brentvatne thanks a bunch! You saved a whole lot of time! :)
dgilliam commentedon Jun 8, 2016
I'm doing this with a pre-existing swift codebase. Using
let jsCodeLocation = NSBundle.mainBundle().URLForResource("main", withExtension: "jsbundle")insideAppDelegate.swiftworkswebdeveloper0429 commentedon Dec 20, 2016
HI @brentvatne!
I did Comment out jsCodeLocation = [NSURL URLWithString:@"http://localhost:8081/index.ios.bundle"];
Uncomment jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
in appdelegate.m
jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index.ios" fallbackResource:nil];
// jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
Btw I get one issue.
"thread 1 signal sigabrt"
I don't know how to fix this?
ezos86 commentedon Apr 13, 2017
this shit does not work .. constantly. - No bundle on anything, It shows locally and in Product the Bundle is there.
creeperyang commentedon Apr 27, 2017
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.
grassmoon commentedon May 2, 2017
Thanks creeperyang! You save my time.
UtenteBello commentedon Jul 3, 2017
I have a issue!
Is possible to run my react native app on iPad with Xcode 8.3 without having the usb cable connected?
Shinchy commentedon Jul 27, 2017
Thanks creeperyang, I can't quite believe that we have to do that to get it working, but it works.
BrunoBerisso commentedon Sep 22, 2017
With
react-native@0.47for iOS I just need to generate the bundle and move it to theiosfolder:$ react-native bundle --platform ios --dev false --entry-file index.ios.js --bundle-output main.jsbundle$ mv main.jsbundle ios/Or better:
$ react-native bundle --platform ios --dev false --entry-file index.ios.js --bundle-output ios/main.jsbundlesiddheshC commentedon May 8, 2018
@creeperyang How do I keep it updated everytime. Once the bundle is created, it never changes. Even after making small changes in index.ios.js, it doesn't get reflected in main.jsbundle.
How to automate that ?