Skip to content

Commit dfc0213

Browse files
committed
doc(ios-phone): ios真机环境安装文档
1 parent cf24910 commit dfc0213

File tree

8 files changed

+87
-0
lines changed

8 files changed

+87
-0
lines changed
61 KB
Loading
7.25 KB
Loading
29.8 KB
Loading
164 KB
Loading
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
iOS 真机环境安装
2+
===
3+
4+
在真机上仔细测试 app 后再发布给用户总是不会错的。本文档将指导你通过必须的步骤在设备上运行 React Native app,为生产做准备
5+
6+
7+
## 在 iOS 设备上运行应用
8+
9+
### 1. 通过 USB 数据线连接设备
10+
11+
使用 USB 闪电数据线连接 iOS 设备到 Mac。导航到工程的ios文件夹,然后用 Xcode 打开.xcworkspace文件,如果是 0.60 以前的版本则打开.xcodeproj文件。
12+
13+
如果这是第一次在 iOS 设备上运行 app,需要注册开发设备。从 Xcode 菜单栏打开Product菜单,然后前往Destination。从列表中查找并选择设备。Xcode 将注册为开发设备。
14+
15+
### 2. 配置代码签名
16+
17+
如果没有[Apple developer account](https://developer.apple.com/),先注册。
18+
19+
在 Xcode Project 导航中选择 project,然后选择 main target(它应该和 project 共享同样的名字)。查找"General"标签。前往"Signing"并确保在"Team"下拉下选择了开发者账号或团队。tests target(以 Tests 结尾,在 main target 下面)也需要重复同样的操作。
20+
21+
![Xcode Project](./001.png)<!--rehype:style=max-width: 480px;-->
22+
23+
### 3. 编译并运行应用
24+
25+
如果一切设置正确,设备会在 Xcode toolbar 中被列为 build target,也会出现在设备面板里(⇧⌘2)。现在可以按下 Build and run 按钮(⌘R)或从Product菜单中选择Run。app 会立刻启动在设备上。
26+
27+
![Xcode toolbar](./002.png)<!--rehype:style=max-width: 480px;-->
28+
29+
> 🚧 注意:如果您遇到任何问题,请查看Apple的“[Launching Your App on a Device](https://help.apple.com/xcode/mac/current/#/dev60b6fbbc7)”文档。
30+
<!--rehype:style=border-left: 8px solid #ffe564;background-color: #ffe56440;padding: 12px 16px;-->
31+
32+
## 从设备上访问开发服务器
33+
34+
在启用开发服务器的情况下,你可以快速的迭代修改应用,然后在设备上立即查看结果。只需要在和电脑同样的 Wi-Fi 网络。摇晃设备打开[Developer menu](https://reactnative.cn/docs/debugging#accessing-the-in-app-developer-menu),然后 enable Live Reload。当 JavaScript 代码改变时 app 会重载。
35+
36+
![Developer menu](./003.png)<!--rehype:style=max-width: 480px;-->
37+
38+
### 常见问题
39+
40+
> 🚧 注意:如果您有任何问题,请确保您的Mac和设备位于同一网络上,并且可以相互连接。许多具有捕获入口的开放式无线网络被配置为防止设备到达网络上的其他设备。在这种情况下,您可以使用设备的个人热点功能。
41+
<!--rehype:style=border-left: 8px solid #ffe564;background-color: #ffe56440;padding: 12px 16px;-->
42+
43+
当尝试连接到开发服务器时,可能得到一个红屏报错说:
44+
45+
> 🚧 注意:Connection to http://localhost:8081/debugger-proxy?role=client timed out. Are you running node proxy? If you are running on the device, check if you have the right IP address in RCTWebSocketExecutor.m.
46+
<!--rehype:style=border-left: 8px solid #ffe564;background-color: #ffe56440;padding: 12px 16px;-->
47+
48+
解决这个问题检查以下几点。
49+
50+
### 1. Wi-Fi 网络
51+
52+
确保笔记本电脑和电话在`同一个`Wi-Fi 网络
53+
54+
### 2. IP 地址
55+
56+
确保编译脚本正确检测到机器的 IP 地址(e.g. 10.0.1.123)。
57+
58+
![](./004.png)
59+
60+
打开`Report navigator`标签,选择最近的`Build`然后搜索`IP=`。搜索到的 `IP` 地址字符串应该和你电脑的 `IP` 地址一致。
61+
62+
## 恭喜
63+
64+
恭喜!您已经用 React Native 编译了一个伟大的 app
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import Preview from 'src/component/Preview';
2+
import md from './README.md';
3+
4+
const transformImageUri = (url: string) => {
5+
const reqImage = (require as any).context!('./', true, /\.(png|gif|jpg|svg)$/);
6+
const urlAddr = reqImage(url);
7+
return urlAddr;
8+
};
9+
10+
const DEMO = () => (
11+
<Preview
12+
{...md}
13+
transformImageUri={transformImageUri}
14+
path="website/src/pages/docs/environment-setup/ios-phone/README.md"
15+
/>
16+
);
17+
export default DEMO;

website/src/routes/menus.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ export const docsMenus: MenuData[] = [
8383
{ path: '/docs/environment-setup/ios', name: 'iOS 环境安装' },
8484
{ path: '/docs/environment-setup/android', name: 'Android(Mac) 环境安装' },
8585
{ path: '/docs/environment-setup/android-windows', name: 'Android(Windows) 环境安装' },
86+
{ path: '/docs/environment-setup/ios-phone', name: 'iOS 真机环境安装' },
87+
8688
{ divider: true, name: 'APP 打包' },
8789
{ path: '/docs/unpack/ios', name: 'iOS 打包' },
8890
{ path: '/docs/unpack/android', name: 'Android(Mac) 打包' },

website/src/routes/router.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ export const routeData = [
3333
path: '/docs/environment-setup/android-windows',
3434
component: lazy(() => import('../pages/docs/environment-setup/android-windows')),
3535
},
36+
{
37+
path: '/docs/environment-setup/ios-phone',
38+
component: lazy(() => import('../pages/docs/environment-setup/ios-phone')),
39+
},
3640
{
3741
path: '/docs/app-store/ios',
3842
component: lazy(() => import('../pages/docs/app-store/ios')),

0 commit comments

Comments
 (0)