Skip to content

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

Closed

Description

@brentvatne

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.

Activity

  1. stolemotion commented on Mar 26, 2015

    @stolemotion

    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.

  2. freshteapot commented on Mar 27, 2015

    @freshteapot

    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.

  3. magus commented on Mar 27, 2015

    @magus

    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 👍

  4. drkibitz commented on Mar 27, 2015

    @drkibitz
    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.

  5. self-assigned this
    on Mar 27, 2015
  6. AgtLucas commented on Mar 27, 2015

    @AgtLucas
    Contributor

    Thanks!

  7. jonaswindey commented on Mar 28, 2015

    @jonaswindey

    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?

  8. AgtLucas commented on Mar 28, 2015

    @AgtLucas
    Contributor

    @jonaswindey

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

  9. jonaswindey commented on Mar 28, 2015

    @jonaswindey

    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.

  10. magus commented on Mar 28, 2015

    @magus

    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.

  11. jordpo commented on Mar 29, 2015

    @jordpo

    Awesome- thank you!

  12. bradoyler commented on Mar 29, 2015

    @bradoyler

    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.
  13. erinjerri commented on Apr 6, 2015

    @erinjerri

    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.

  14. erinjerri commented on Apr 6, 2015

    @erinjerri

    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

  15. 10 remaining items

  16. frantic commented on Feb 5, 2016

    @frantic
    Contributor

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

  17. lkaihua commented on Feb 11, 2016

    @lkaihua

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

  18. joshuapinter commented on Feb 22, 2016

    @joshuapinter
    Contributor
  19. mihir0x69 commented on Feb 25, 2016

    @mihir0x69

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

  20. dgilliam commented on Jun 8, 2016

    @dgilliam

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

  21. webdeveloper0429 commented on Dec 20, 2016

    @webdeveloper0429

    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?

  22. ezos86 commented on Apr 13, 2017

    @ezos86

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

  23. creeperyang commented on Apr 27, 2017

    @creeperyang

    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.

  24. grassmoon commented on May 2, 2017

    @grassmoon

    Thanks creeperyang! You save my time.

  25. UtenteBello commented on Jul 3, 2017

    @UtenteBello

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

  26. Shinchy commented on Jul 27, 2017

    @Shinchy

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

  27. BrunoBerisso commented on Sep 22, 2017

    @BrunoBerisso

    With react-native@0.47 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

  28. siddheshC commented on May 8, 2018

    @siddheshC

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

  29. locked as resolved and limited conversation to collaborators on May 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions