HarmonyOS connection.createNetConnection\(\)监听网络状态变化出错?

netCon: connection.NetConnection = connection.createNetConnection()
netCon.register((error: BusinessError) => {
  LoggerUtil.info(TAG, "register --> " + JSON.stringify(error));
});

出现错误:

{"code":2101022,"message":"the number of requests exceeded the maximum”}
阅读 521
1 个回答

当前报错返回2101022可能是没有调用unregister导致请求数量超过最大值,可在请求完成监听时添加that.netConnection.unregister取消监听。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进