React native - 连接没有连接处理程序错误含义?
React native - connection has no connection handler error meaning?
我创建了一个新的 React 项目,当我从 xcode 在 iOS 上 运行 它时,控制台给了我这个:
2017-05-19 23:25:34.119 [info][tid:main][RCTBatchedBridge.m:77] Initializing <RCTBatchedBridge: 0x6100001a6c80> (parent: <RCTBridge: 0x6100000c46e0>, executor: RCTJSCExecutor)
2017-05-19 23:25:51.287 [info][tid:main][RCTRootView.m:295] Running application test ({
initialProps = {
};
rootTag = 1;
})
2017-05-19 23:25:51.289 [info][tid:com.facebook.react.JavaScript] Running application "test" with appParams: {"rootTag":1,"initialProps":{}}. __DEV__ === true, development-level warning are ON, performance optimizations are OFF
2017-05-19 23:25:51.299771-0400 test[21948:1121429] [] nw_connection_get_connected_socket_block_invoke 3 Connection has no connected handler
2017-05-19 23:25:53.335282-0400 test[21948:1121426] [] nw_connection_get_connected_socket_block_invoke 4 Connection has no connected handler
2017-05-19 23:25:55.349190-0400 test[21948:1120112] [] nw_connection_get_connected_socket_block_invoke 5 Connection has no connected handler
这些行 2017-05-19 23:25:51.299771-0400 test[21948:1121429] [] nw_connection_get_connected_socket_block_invoke 3 Connection has no connected handler
是什么意思,我该如何解决这个问题?
当我尝试在我的应用程序中使用 fetch 并发现它不起作用时,我第一次注意到了这一点。我在控制台中发现了这些消息,后来发现这些消息出现在我的所有应用程序中,所以我认为这意味着这是我的配置问题?
我创建了一个新的测试程序来测试导致此问题的原因,并发现它发生在一个全新的项目中。下面是我的代码是生成上面的日志输出:
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View
} from 'react-native';
export default class test extends Component {
render() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>
Welcome to React Native!
</Text>
<Text style={styles.instructions}>
To get started, edit index.ios.js
</Text>
<Text style={styles.instructions}>
Press Cmd+R to reload,{'\n'}
Cmd+D or shake for dev menu
</Text>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
});
AppRegistry.registerComponent('test', () => test);
尝试以下流程
Xcode 菜单 -> 产品 -> 编辑方案...
环境变量 -> 添加 -> 名称:"OS_ACTIVITY_MODE",值:"disable"
运行 又是你的应用
这个错误很可能来自内置于 react-native 中的 websocket,用于连接到 react-devtools。如果你在调试时没有 运行 react-devtools,那么你会得到这个错误,它还会在桥上发送一堆消息抱怨无法打开 websocket(你只会看到那些错误如果您使用 rn-snoopy).
只要您安装并打开 react-devtools,该错误就会停止。请参阅这些说明以了解如何操作:
https://github.com/facebook/react-devtools/blob/master/packages/react-devtools/README.md
在我的例子中,这是由于防火墙应用程序 (Little Snitch) 在 运行 来自 react-native 应用程序时从不请求访问。适合我的步骤:
- 在模拟器中打开Safari浏览器
- 访问google.com或任何域
- 确保它能打开页面。它会要求访问等
- 在模拟器中重启您的应用程序
- 重新开始记录
react-native log-ios
这应该有所帮助。
我找到了解决方案:
为 OS Activity 模式关闭 Verbose
- 从 xcode 菜单中,项目 -> 方案 -> 编辑方案。
- 然后是 select
Run
在左边,然后是 select Arguments
选项卡在右边。
- 在
Environment Variables
中添加名称 OS_ACTIVITY_MODE
和值 disable
。
或见下图
注意:图片归功于
为了禁用 websocket 流,我执行了以下操作:
in xcode: Libraries/React.xcodeproj/React/Inspector/RCTInspectorPackagerConnection.m: 找到 - (void)connect {
并在其后添加 return;
.
in node_modules/react-native/Libraries/Core/Devtools/setupDevtools.js: 将 if (__DEV__)
替换为 if (false)
这很丑陋,但比 OS_ACTIVITY 解决方案好很多,因为它不会隐藏或阻止任何其他调试工具。
我遇到了同样的问题,我的应用程序的启动因为这个问题而显着延迟。对我的实际修复是详细的 here,但我会重写它以防 link 中断:
- 打开Xcode
- 单击顶部栏上的
Product
- 单击
Scheme
,向下滚动到 Edit Scheme
- Select
Run
在左侧栏上,Info
在顶部选项卡上
- 将
Build Configuration
从 Debug
更改为 Release
现在应用程序不仅不再有错误,而且启动速度更快。另一个"fixes"只是隐藏错误。
我创建了一个新的 React 项目,当我从 xcode 在 iOS 上 运行 它时,控制台给了我这个:
2017-05-19 23:25:34.119 [info][tid:main][RCTBatchedBridge.m:77] Initializing <RCTBatchedBridge: 0x6100001a6c80> (parent: <RCTBridge: 0x6100000c46e0>, executor: RCTJSCExecutor)
2017-05-19 23:25:51.287 [info][tid:main][RCTRootView.m:295] Running application test ({
initialProps = {
};
rootTag = 1;
})
2017-05-19 23:25:51.289 [info][tid:com.facebook.react.JavaScript] Running application "test" with appParams: {"rootTag":1,"initialProps":{}}. __DEV__ === true, development-level warning are ON, performance optimizations are OFF
2017-05-19 23:25:51.299771-0400 test[21948:1121429] [] nw_connection_get_connected_socket_block_invoke 3 Connection has no connected handler
2017-05-19 23:25:53.335282-0400 test[21948:1121426] [] nw_connection_get_connected_socket_block_invoke 4 Connection has no connected handler
2017-05-19 23:25:55.349190-0400 test[21948:1120112] [] nw_connection_get_connected_socket_block_invoke 5 Connection has no connected handler
这些行 2017-05-19 23:25:51.299771-0400 test[21948:1121429] [] nw_connection_get_connected_socket_block_invoke 3 Connection has no connected handler
是什么意思,我该如何解决这个问题?
当我尝试在我的应用程序中使用 fetch 并发现它不起作用时,我第一次注意到了这一点。我在控制台中发现了这些消息,后来发现这些消息出现在我的所有应用程序中,所以我认为这意味着这是我的配置问题?
我创建了一个新的测试程序来测试导致此问题的原因,并发现它发生在一个全新的项目中。下面是我的代码是生成上面的日志输出:
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View
} from 'react-native';
export default class test extends Component {
render() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>
Welcome to React Native!
</Text>
<Text style={styles.instructions}>
To get started, edit index.ios.js
</Text>
<Text style={styles.instructions}>
Press Cmd+R to reload,{'\n'}
Cmd+D or shake for dev menu
</Text>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
});
AppRegistry.registerComponent('test', () => test);
尝试以下流程
Xcode 菜单 -> 产品 -> 编辑方案...
环境变量 -> 添加 -> 名称:"OS_ACTIVITY_MODE",值:"disable"
运行 又是你的应用
这个错误很可能来自内置于 react-native 中的 websocket,用于连接到 react-devtools。如果你在调试时没有 运行 react-devtools,那么你会得到这个错误,它还会在桥上发送一堆消息抱怨无法打开 websocket(你只会看到那些错误如果您使用 rn-snoopy).
只要您安装并打开 react-devtools,该错误就会停止。请参阅这些说明以了解如何操作: https://github.com/facebook/react-devtools/blob/master/packages/react-devtools/README.md
在我的例子中,这是由于防火墙应用程序 (Little Snitch) 在 运行 来自 react-native 应用程序时从不请求访问。适合我的步骤:
- 在模拟器中打开Safari浏览器
- 访问google.com或任何域
- 确保它能打开页面。它会要求访问等
- 在模拟器中重启您的应用程序
- 重新开始记录
react-native log-ios
这应该有所帮助。
我找到了解决方案:
为 OS Activity 模式关闭 Verbose
- 从 xcode 菜单中,项目 -> 方案 -> 编辑方案。
- 然后是 select
Run
在左边,然后是 selectArguments
选项卡在右边。 - 在
Environment Variables
中添加名称OS_ACTIVITY_MODE
和值disable
。
或见下图
注意:图片归功于
为了禁用 websocket 流,我执行了以下操作:
in xcode: Libraries/React.xcodeproj/React/Inspector/RCTInspectorPackagerConnection.m: 找到
- (void)connect {
并在其后添加return;
.in node_modules/react-native/Libraries/Core/Devtools/setupDevtools.js: 将
if (__DEV__)
替换为if (false)
这很丑陋,但比 OS_ACTIVITY 解决方案好很多,因为它不会隐藏或阻止任何其他调试工具。
我遇到了同样的问题,我的应用程序的启动因为这个问题而显着延迟。对我的实际修复是详细的 here,但我会重写它以防 link 中断:
- 打开Xcode
- 单击顶部栏上的
Product
- 单击
Scheme
,向下滚动到Edit Scheme
- Select
Run
在左侧栏上,Info
在顶部选项卡上 - 将
Build Configuration
从Debug
更改为Release
现在应用程序不仅不再有错误,而且启动速度更快。另一个"fixes"只是隐藏错误。