Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation missing instructions for running on device via static bundle #240

Closed
brentvatne opened this issue Mar 26, 2015 · 35 comments · Fixed by #625
Closed

Documentation missing instructions for running on device via static bundle #240

brentvatne opened this issue Mar 26, 2015 · 35 comments · Fixed by #625
Assignees
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@brentvatne
Copy link
Collaborator

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.

@stolemotion
Copy link

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
Copy link

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
Copy link

magus commented 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
Copy link
Contributor

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.

@frantic frantic self-assigned this Mar 27, 2015
@AgtLucas
Copy link
Contributor

Thanks!

@jonaswindey
Copy link

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
Copy link
Contributor

@jonaswindey

As far as I know, this is impossible, Apple doesn't allow this.

@jonaswindey
Copy link

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
Copy link

magus commented 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
Copy link

jordpo commented Mar 29, 2015

Awesome- thank you!

@bradoyler
Copy link

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.

@erinjerri
Copy link

image
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
Copy link

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

@erinjerri
Copy link

Still getting the same error even after doing what was referenced in stackoverflow in my last post. Thoughts?

vjeux pushed a commit to vjeux/react-native that referenced this issue Apr 13, 2015
Summary:
This helps generating offline bundles by adding almost empty main.jsbundle to
the app. The only thing left is to fetch minified bundle from server and save it
to the file, then flip the switch in AppDelegate.

I'll add docs about this soon.

facebook#240

Test Plan:
Did the `curl` command from comments. Changed URL to be local file,
started SampleApp, works fine without server.
@DanielAsher
Copy link

@brentvatne this works! many thanks 👍

@crobinson
Copy link

on your app dir run react-native bundle --minify

@joshbuchea
Copy link
Contributor

@brentvatne works great for me also. Thanks 👍

@BenjaminConant
Copy link

@brentvatne thanks for the issue ... followed the instructions and seems that the curl requests needs to be curl "http://localhost:8081/index.ios.bundle?platform=ios" -o main.jsbundle now as a there needs to be a platform specified .... These instructions are almost working for me but when I try to build the app I am getting an error from the dev console

Uncaught NetworkError: Failed to execute 'importScripts' on 'WorkerGlobalScope': The script at 'file:///Users/benconant/Library/Developer/CoreSimulator/Devices/3054F999-82…2766-011B-4294-AB40-4043145DD443/Eastern%20Car%20Service.app/main.jsbundle' failed to load.messageHandlers.executeApplicationScript @ debuggerWorker.js:18onmessage @ debuggerWorker.js:42

have you seen this before ... can't figure out what might be causing it

Also made a SO question that has more specific info ... though no answer yet

http://stackoverflow.com/questions/34187094/react-native-ios-loading-from-pre-budled-file-fails

@lrettig
Copy link
Contributor

lrettig commented Jan 19, 2016

Another issue not discussed in this thread which can also cause the "Could not connect to development server" error is App Transport Security (ATS) in iOS9. This should be mentioned in the instructions as well. Cf. http://stackoverflow.com/a/34880394/2397068

@lkaihua
Copy link

lkaihua commented Feb 3, 2016

@satya164 In my perspective the document is still confusing about curl steps for offline jsbundle. That's why I also ended up in this page.

I tried both the method mentioned above and also the bundle function in cli. If possible please add following example in the section Using Offline Bundle, would save quite a few efforts for starters.

react-native bundle --platfrom ios --dev false --entry-file index.ios.js \
        --bundle-output main.jsbundle

@satya164
Copy link
Contributor

satya164 commented Feb 3, 2016

@kainliu AFAIK the bundle is automatically generated while generating the package.

@frantic
Copy link
Contributor

frantic commented 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
Copy link

lkaihua commented Feb 11, 2016

@frantic @satya164 The sh script works quite well and thanks for pointing out the shortcoming.

@joshuapinter
Copy link
Contributor

@satya164 👍

@mihir0x69
Copy link

@brentvatne thanks a bunch! You saved a whole lot of time! :)

@dgilliam
Copy link

dgilliam commented Jun 8, 2016

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

@webdeveloper0429
Copy link

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
Copy link

ezos86 commented Apr 13, 2017

this shit does not work .. constantly. - No bundle on anything, It shows locally and in Product the Bundle is there.

@creeperyang
Copy link

creeperyang commented Apr 27, 2017

Currently ([email protected]), 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.

@grassmoon
Copy link

Thanks creeperyang! You save my time.

@UtenteBello
Copy link

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
Copy link

Shinchy commented Jul 27, 2017

Thanks creeperyang, I can't quite believe that we have to do that to get it working, but it works.

@BrunoBerisso
Copy link

With [email protected] for iOS I just need to generate the bundle and move it to the ios folder:

  • $ 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.jsbundle

@siddheshC
Copy link

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

@facebook facebook locked as resolved and limited conversation to collaborators May 29, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 23, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

Successfully merging a pull request may close this issue.