react-native/docs/RunningOnDeviceIOS.md

54 lines
2.9 KiB
Markdown
Raw Normal View History

2015-04-02 17:41:22 +00:00
---
id: running-on-device-ios
title: Running On Device
2015-04-02 17:41:22 +00:00
layout: docs
category: Guides (iOS)
permalink: docs/running-on-device-ios.html
next: embedded-app-ios
2015-04-02 17:41:22 +00:00
---
Note that running on device requires [Apple Developer account](https://developer.apple.com/register) and provisioning your iPhone. This guide covers only React Native specific topic.
2015-04-02 17:41:22 +00:00
## Accessing development server from device
You can iterate quickly on device using development server. To do that, your laptop and your phone have to be on the same wifi network.
2015-09-19 20:56:21 +00:00
1. Open `AwesomeApp/ios/AwesomeApp/AppDelegate.m`
2015-10-17 09:26:58 +00:00
2. Change the IP in the URL from `localhost` to your laptop's IP. On Mac, you can find the IP address in System Preferences / Network.
2015-04-02 17:41:22 +00:00
3. In Xcode select your phone as build target and press "Build and run"
> Hint
>
> Shake the device to open development menu (reload, debug, etc.)
2015-04-02 17:41:22 +00:00
## Using offline bundle
You can also pack all the JavaScript code within the app itself. This way you can test it without development server running and submit the app to the AppStore.
2015-09-19 20:56:21 +00:00
1. Open `AwesomeApp/ios/AwesomeApp/AppDelegate.m`
2015-04-02 17:41:22 +00:00
2. Follow the instructions for "OPTION 2":
* Uncomment `jsCodeLocation = [[NSBundle mainBundle] ...`
2016-01-13 03:35:01 +00:00
* Run the `react-native bundle --platform ios --dev false --entry-file index.ios.js --bundle-output iOS/main.jsbundle` command in terminal from the root directory of your app
2015-04-02 17:41:22 +00:00
2015-04-21 00:00:39 +00:00
The bundle script supports a couple of flags:
2015-04-02 17:41:22 +00:00
* `--dev` - a boolean with a default value of `true`. With the `--dev true` flag, the bundled JavaScript code turns on useful development warnings and limits performance optimizations. For production it is recommended to pass `--dev false`. Also for production, be sure to have your native build configuration set to `Release` (e.g., Xcode's Release configuration for iOS and gradle's `assembleRelease` task for Android) in order to disable things like the shake-to-show developer menu.
2015-04-21 00:00:39 +00:00
* `--minify` - pipe the JS code through UglifyJS.
2015-04-02 17:41:22 +00:00
2015-10-13 19:08:11 +00:00
Note that on 0.14 we'll change the API of `react-native bundle`. The major changes are:
2015-10-13 19:41:42 +00:00
2015-10-13 19:08:11 +00:00
* API is now `entry-file <path>` based instead of url based.
* Need to specify which platform you're bundling for `--platform <ios|android>`.
* Option `--out` has been renamed for `--bundle-output`.
* Source maps are no longer automatically generated. Need to specify `--sourcemap-output <path>`
2015-04-29 23:59:50 +00:00
## Disabling in-app developer menu
When building your app for production, your app's scheme should be set to `Release` as detailed in [the debugging documentation](/react-native/docs/debugging.html#debugging-react-native-apps) in order to disable the in-app developer menu.
2015-04-02 17:41:22 +00:00
## Troubleshooting
If `curl` command fails make sure the packager is running. Also try adding `--ipv4` flag to the end of it.
If you started your project a while ago, `main.jsbundle` might not be included into Xcode project. To add it, right click on your project directory and click "Add Files to ..." - choose the `main.jsbundle` file that you generated.