diff --git a/zh-cn/react-native-community-netinfo.md b/zh-cn/react-native-community-netinfo.md index 2ae2054effcf4e81eaf8f70d65317a683c8fd362..1dc2f10448c2e58ef76943cd6c4c8e25ee01b29b 100644 --- a/zh-cn/react-native-community-netinfo.md +++ b/zh-cn/react-native-community-netinfo.md @@ -1,4 +1,3 @@ - > 模板版本:v0.2.2
@@ -49,27 +48,27 @@ import { View, Text } from "react-native";
import NetInfo, { useNetInfo } from "@react-native-community/netinfo";
const App = () => {
- const [fetchInfo, setFetchInfo] = React.useState("");
- const [refreshInfo, setRefreshInfo] = React.useState("");
- const netInfo = useNetInfo();
-
- NetInfo.fetch().then((state) => {
- setFetchInfo(JSON.stringify(state));
- });
- NetInfo.refresh().then((state) => {
- setRefreshInfo(JSON.stringify(state));
- });
-
- return (
-
Defaults to null on most platforms for unknown networks.
Note: Web browsers report network type unknown for many otherwise valid networks (https://caniuse.com/netinfo),
so isConnected may be true or false and represent a real connection status even for unknown network types in certain cases. | boolean, null | yes | iOS Android | yes |
+| `isInternetReachable` | If the internet is reachable with the currently active network connection.
If unknown defaults to null | boolean, null | yes | iOS Android | yes |
+| `isWifiEnabled` | (Android only) Whether the device's WiFi is ON or OFF. | boolean | yes | iOS Android | yes |
+| `details` | The value depends on the type value. See below. | | yes | iOS Android | yes |
### Details
-#### Type is none or unknown
-
-`details` is `null`.
-
#### Type is wifi
-| Name | Description | Type | Required | Platform | HarmonyOS Support |
-| ----------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- | -------- | ---------------------------------- | ----------------- |
-| `isConnectionExpensive` | If the network connection is considered "expensive". This could be in either energy or monetary terms. | boolean | yes | All | yes |
-| `ssid` | The SSID of the network. May not be present, null, or an empty string if it cannot be determined. On iOS, your app must meet at least one of the following requirements and you must set the shouldFetchWiFiSSID configuration option or no attempt will be made to fetch the SSID. On Android, you need to have the ACCESS_FINE_LOCATION permission in your AndroidManifest.xml and accepted by the user. | string | yes | Android, iOS (not tvOS), Windows | yes |
-| `bssid` | The BSSID of the network. May not be present, null, or an empty string if it cannot be determined. On iOS, make sure your app meets at least one of the following requirements. On Android, you need to have the ACCESS_FINE_LOCATION permission in your AndroidManifest.xml and accepted by the user. | string | yes | Android, iOS (not tvOS), Windows\* | yes |
-| `strength` | An integer number from 0 to 100 for the signal strength. May not be present if the signal strength cannot be determined. | number | yes | Android, Windows | yes |
-| `ipAddress` | The external IP address. Can be in IPv4 or IPv6 format. May not be present if it cannot be determined. | string | yes | Android, iOS, macOS, Windows | yes |
-| `subnet` | The subnet mask in IPv4 format. May not be present if it cannot be determined. | string | yes | Android, iOS, macOS | yes |
-| `frequency` | Network frequency. Example: For 2.4 GHz networks, the method will return 2457. May not be present if it cannot be determined. | number | yes | Android, Windows\* | yes |
-| `linkSpeed` | The link speed in Mbps. | number | yes | Android | yes |
-| `rxLinkSpeed` | The current receive link speed in Mbps. | number | yes | Android | yes |
-| `txLinkSpeed` | The current transmit link speed in Mbps. | number | yes | Android | yes |
+| Name | Description | Type | Required | Platform | HarmonyOS Support |
+|-------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------|----------|-------------|-------------------|
+| `isConnectionExpensive` | If the network connection is considered "expensive".
This could be in either energy or monetary terms. | boolean | yes | iOS Android | yes |
+| `ssid` | The SSID of the network.
May not be present, null, or an empty string if it cannot be determined.
On iOS, your app must meet at least one of the following requirements and you must set the shouldFetchWiFiSSID configuration option or no attempt will be made to fetch the SSID.
On Android, you need to have the ACCESS_FINE_LOCATION permission in your AndroidManifest.
xml and accepted by the user. | string | yes | iOS Android | yes |
+| `bssid` | The BSSID of the network.
May not be present, null, or an empty string if it cannot be determined.
On iOS, make sure your app meets at least one of the following requirements.
On Android, you need to have the ACCESS_FINE_LOCATION permission in your AndroidManifest.
xml and accepted by the user. | string | yes | iOS Android | yes |
+| `strength` | An integer number from 0 to 100 for the signal strength.
May not be present if the signal strength cannot be determined. | number | yes | Android | yes |
+| `ipAddress` | The external IP address. Can be in IPv4 or IPv6 format.
May not be present if it cannot be determined. | string | yes | iOS Android | yes |
+| `subnet` | The subnet mask in IPv4 format.
May not be present if it cannot be determined. | string | yes | iOS Android | yes |
+| `frequency` | Network frequency. Example: For 2.4 GHz networks, the method will return 2457.
May not be present if it cannot be determined. | number | yes | Android | yes |
+| `linkSpeed` | The link speed in Mbps. | number | yes | Android | yes |
+| `rxLinkSpeed` | The current receive link speed in Mbps. | number | yes | Android | yes |
+| `txLinkSpeed` | The current transmit link speed in Mbps. | number | yes | Android | yes |
#### Type is cellular
-| Name | Description | Type | Required | Platform | HarmonyOS Support |
-| ----------------------- | --------------------------------------------------------------------------------------------------------------------- | :-----------------------: | :------: | :-------------------: | :---------------: |
-| `isConnectionExpensive` | If the network connection is considered "expensive". This could be in either energy or monetary terms. | boolean | yes | All | no |
-| `cellularGeneration` | The generation of the cell network the user is connected to. This can give an indication of speed, but no guarantees. | NetInfoCellularGeneration | yes | Android, iOS, Windows | no |
-| `carrier` | The network carrier name. May not be present or may be empty if none can be determined. | +string | yes | Android, iOS | no |
+| Name | Description | Type | Required | Platform | HarmonyOS Support |
+|-------------------------|-----------------------------------------------------------------------------------------------------------------------|:-------------------------:|:--------:|:-----------:|:-----------------:|
+| `isConnectionExpensive` | If the network connection is considered "expensive". This could be in either energy or monetary terms. | boolean | yes | iOS Android | no |
+| `cellularGeneration` | The generation of the cell network the user is connected to. This can give an indication of speed, but no guarantees. | NetInfoCellularGeneration | yes | iOS Android | no |
+| `carrier` | The network carrier name. May not be present or may be empty if none can be determined. | +string | yes | iOS Android | no |
#### Type is bluetooth, ethernet, wimax, vpn, or other
-| Name | Description | Type | Required | Platform | HarmonyOS Support |
-| ----------------------- | ------------------------------------------------------------------------------------------------------ | :-----: | :------: | :------: | :---------------: |
-| `isConnectionExpensive` | If the network connection is considered "expensive". This could be in either energy or monetary terms. | boolean | yes | All | no |
+| Name | Description | Type | Required | Platform | HarmonyOS Support |
+|-------------------------|-------------------------------------------------------------------------------------------------------------|:-------:|:--------:|:-----------:|:-----------------:|
+| `isConnectionExpensive` | If the network connection is considered "expensive".
This could be in either energy or monetary terms. | boolean | yes | iOS Android | no |
## 静态方法
-| Name | Description | Type | Required | Platform | HarmonyOS Support |
-| ---------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :------: | :------: | :------: | :---------------: |
-| `fetch()` | Returns a Promise that resolves to a NetInfoState object. | function | yes | All | yes |
-| `refresh()` | Updates NetInfo's internal state, then returns a Promise that resolves to a NetInfoState object. This is similar to fetch(), but really only useful on platforms that do not supply internet reachability natively. For example, you can use it to immediately re-run an internet reachability test if a network request fails unexpectedly. | function | yes | All | yes |
-| `addEventListener()` | Subscribe to connection information. The callback is called with a parameter of type NetInfoState whenever the connection state changes. Your listener will be called with the latest information soon after you subscribe and then with any subsequent changes afterwards. You should not assume that the listener is called in the same way across devices or platforms. | function | yes | All | yes |
-| `useNetInfo()` | A React Hook which can be used to get access to the latest state from the global instance. It returns a hook with the NetInfoState type. | function | yes | All | yes |
-| `useNetInfoInstance()` | A React Hook which can be used to create and manage an isolated instance of a network manager class. It returns a refresh function and the current NetInfoState. | function | yes | All | yes |
+> [!tip] "Platform"列表示该属性在原三方库上支持的平台。
+
+> [!tip] "HarmonyOS Support"列为 yes 表示 HarmonyOS 平台支持该属性;no 则表示不支持;partially 表示部分支持。使用方法跨平台一致,效果对标 iOS 或 Android 的效果。
+
+| Name | Description | Type | Required | Platform | HarmonyOS Support |
+|------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|:--------:|:--------:|:-----------:|:-----------------:|
+| `fetch()` | Returns a Promise that resolves to a NetInfoState object. | function | yes | iOS Android | yes |
+| `refresh()` | Updates NetInfo's internal state, then returns a Promise that resolves to a NetInfoState object.
This is similar to fetch(), but really only useful on platforms that do not supply internet reachability natively.
For example, you can use it to immediately re-run an internet reachability test if a network request fails unexpectedly. | function | yes | iOS Android | yes |
+| `addEventListener()` | Subscribe to connection information.
The callback is called with a parameter of type NetInfoState whenever the connection state changes.
Your listener will be called with the latest information soon after you subscribe and then with any subsequent changes afterwards.
You should not assume that the listener is called in the same way across devices or platforms. | function | yes | iOS Android | yes |
+| `useNetInfo()` | A React Hook which can be used to get access to the latest state from the global instance.
It returns a hook with the NetInfoState type. | function | yes | iOS Android | yes |
+| `useNetInfoInstance()` | A React Hook which can be used to create and manage an isolated instance of a network manager class.
It returns a refresh function and the current NetInfoState. | function | yes | iOS Android | yes |
## 遗留问题
-- 涉及非 wifi 环境下的接口属性未适配
+- [ ] 涉及非 wifi 环境下的接口属性未适配: [issue#](https://github.com/issue地址1)
## 其他
## 开源协议
本项目基于 [The MIT License (MIT)](https://github.com/react-native-netinfo/react-native-netinfo/blob/master/LICENSE) ,请自由地享受和参与开源。
-
-
\ No newline at end of file