id | title | layout | category | permalink | next |
---|---|---|---|---|---|
getting-started |
Getting Started |
docs |
Quick Start |
docs/getting-started.html |
tutorial |
- OS X - This repo only contains the iOS implementation right now, and Xcode only runs on Mac.
- New to Xcode? Download it from the Mac App Store.
- Homebrew is the recommended way to install node, watchman, and flow.
brew install node
. New to node or npm?brew install watchman
. We recommend installing watchman, otherwise you might hit a node file watching bug.brew install flow
. If you want to use flow.
npm install -g react-native-cli
react-native init AwesomeProject
In the newly created folder AwesomeProject/
- Open
AwesomeProject.xcodeproj
and hit run in Xcode - Open
index.ios.js
in your text editor of choice and edit some lines - Hit cmd+R (twice) in your iOS simulator to reload the app and see your change!
Congratulations! You've just successfully run and modified your first React Native app.
- OS X,目前仅包含了iOS的实现,Xcode只在Mac上才能运行
- 开发者可以从Mac应用商店下载Xcode
- Node或者npm的新手可以通过
brew install node
来安装Node.js brew install watchman
. 我们建议安装watchman,否则你可能会遇到node
的文件监控bug- 如果你想使用flow,可以通过
brew install flow
npm install -g react-native-cli
react-native init AwesomeProject
在AwesomeProject/
目录中执行如下操作:
- 打开
AwesomeProkect.xcodeproj
,然在在Xcode
中点击run
运行 - 用文本编辑器打开
index.ios.js
,编辑一些代码 - 在iOS simulator中按cmd + R(twice)来重载APP,并且观察之前的改动
恭喜!您刚刚成功的运行并且编写了您第一个React Native应用。
额外有一步操作在官方文档中没有体现,否则会运行失败。具体如下,两种方式任选一种:
打开项目中的AppDelegate.m
- 方式一:找到这行代码:jsCodeLocation = [NSURL URLWithString:@"http://
localhost
:8081/index.ios.bundle"],将localhost换成自己的ip - 方式二:
- 注释掉方式一中的代码
- 去掉
jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
前面的注释。 - run
npm start
- run
curl http://localhost:8081/index.ios.bundle -o main.jsbundle
如果失败的话在后面加上--ipv4
- 在XCode中,右击你的项目文件夹,点击
New file
,选择你生成的main.jsbundle
。
- 推荐第一个方法比较简单。
- 现在就可以在无无服务器的环境下运行你的app拉。