From febfb5f5e425b4cd301434de7d3976ad8e3b4ea3 Mon Sep 17 00:00:00 2001 From: ZZZH Date: Sun, 4 Jan 2026 20:48:33 +0800 Subject: [PATCH 01/17] =?UTF-8?q?docs:=20[Issues:=20#IDHIT7]=E6=96=B0?= =?UTF-8?q?=E5=A2=9Ereact-native-wifi-reborn=E7=9A=84=E4=B8=AD=E8=8B=B1?= =?UTF-8?q?=E6=96=87=E6=8C=87=E5=AF=BC=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- en/react-native-wifi-reborn.md | 969 ++++++++++++++++++++++++++++++ zh-cn/react-native-wifi-reborn.md | 967 +++++++++++++++++++++++++++++ 2 files changed, 1936 insertions(+) create mode 100644 en/react-native-wifi-reborn.md create mode 100644 zh-cn/react-native-wifi-reborn.md diff --git a/en/react-native-wifi-reborn.md b/en/react-native-wifi-reborn.md new file mode 100644 index 00000000..ea4333f3 --- /dev/null +++ b/en/react-native-wifi-reborn.md @@ -0,0 +1,969 @@ +> Template Version: v0.2.2 + +

+

react-native-wifi-reborn

+

+ +Please check the release information of the corresponding version at the third-party library's Releases page: + +| Third-Party Library Version | Release Information | Supported RN Version | +| --------------------------- | --------------------------------------------------------------- | -------------------- | +| 0.6.1 | [@react-native-ohos/react-native-wifi-reborn Releases](https://github.com/react-native-oh-library/react-native-wifi-reborn/releases) | 0.72 | +| 0.7.0 | [@react-native-ohos/react-native-wifi-reborn Releases](https://github.com/react-native-oh-library/react-native-wifi-reborn/releases) | 0.77 | + +> [!TIP] [GitHub Address](https://github.com/react-native-oh-library/react-native-wifi-reborn) + +## Installation and Usage + +Navigate to the project directory and enter the following command: + + + + +#### npm + +```bash +npm install @react-native-ohos/react-native-wifi-reborn +``` + +#### yarn + +```bash +yarn add @react-native-ohos/react-native-wifi-reborn +``` + + + +The following code demonstrates the basic usage scenarios of this library: + +> [!WARNING] The library name used in the import remains unchanged. +### wifi-reborn example +``` js +import React, { useState } from 'react'; +import { ScrollView, StyleSheet, Text, TouchableOpacity, View, TextInput, Alert } from 'react-native'; +import { Tester, TestSuite, TestCase } from '@rnoh/testerino'; +import WifiManager from 'react-native-wifi-reborn'; +import RTNPermissions, { Permission } from "react-native-permissions"; + +const permissionNormal: Permission[] = [ + 'ohos.permission.GET_WIFI_INFO', + 'ohos.permission.SET_WIFI_INFO', + 'ohos.permission.LOCATION', + 'ohos.permission.MANAGE_WIFI_CONNECTION', + 'ohos.permission.GET_WIFI_LOCAL_MAC', + 'ohos.permission.APPROXIMATELY_LOCATION', +]; + +const COLORS = { + primary: '#007AFF', + secondary: '#5856D6', + success: '#4CD964', + background: '#F2F2F7', + card: '#FFFFFF', + text: '#000000', + subText: '#8E8E93', + border: '#C7C7CC', + error: '#FF3B30', +}; + +const CustomButton = ({ title, onPress, color = COLORS.primary }: { title: string, onPress: () => void, color?: string }) => ( + + {title} + +); + +const ResultArea = ({ text }: { text: string }) => { + if (!text) return null; + return ( + + Result: + {text} + + ); +}; + +const Description = ({ text }: { text: string }) => ( + {text} +); + +export const TurboLogDemoTest = () => { + const [wifiList, setWifiList] = useState([]); + const [ssid, setSsid] = useState(''); + const [password, setPassword] = useState(''); + const [log, setLog] = useState(''); + const [results, setResults] = useState<{ [key: string]: string }>({}); + + const addLog = (msg: string) => { + console.info(msg); + setLog(prev => msg + '\n' + prev); + }; + + const updateResult = (key: string, value: string) => { + setResults(prev => ({ ...prev, [key]: value })); + addLog(`${key}: ${value}`); + }; + + const safeStringify = (val: any) => { + if (typeof val === 'string') return val; + try { + return JSON.stringify(val, null, 2); + } catch (e) { + return String(val); + } + }; + + return ( + + + + Wifi Manager Demo + + + + + + + + + + + { + try { + let requestMultiple = await RTNPermissions.requestMultiple(permissionNormal); + updateResult("Permissions", safeStringify(requestMultiple)); + } catch (e) { + updateResult("Permissions", "Error: " + safeStringify(e)); + } + }} + /> + + + + + + + + + + { + WifiManager.loadWifiList().then((list: any) => { + updateResult("loadWifiList", "Loaded " + list.length + " networks"); + setWifiList(list); + }).catch((err: any) => updateResult("loadWifiList", "Error: " + safeStringify(err))); + }} + /> + + + + + + + { + WifiManager.reScanAndLoadWifiList().then((list: any) => { + updateResult("reScanAndLoadWifiList", "Loaded " + list.length + " networks"); + setWifiList(list); + }).catch((err: any) => updateResult("reScanAndLoadWifiList", "Error: " + safeStringify(err))); + }} + /> + + + + {wifiList.length > 0 && ( + + Available Networks + {wifiList.map((item, index) => ( + { + setSsid(item.SSID); + addLog("Selected SSID: " + item.SSID); + }} + > + + {item.SSID || ''} + {item.level} dBm + + {item.BSSID} + {item.capabilities} + + ))} + + )} + + + + + + + { + addLog(`Connecting to ${ssid}...`); + WifiManager.connectToProtectedSSID(ssid, password, false, false) + .then(() => updateResult("connectToProtectedSSID", "Connected to " + ssid)) + .catch((err: any) => updateResult("connectToProtectedSSID", "Error: " + safeStringify(err))); + }} + /> + + + + + + + { + addLog(`Connecting to ${ssid} with options...`); + WifiManager.connectToProtectedWifiSSID({ + ssid: ssid, + password: password, + isWEP: false, + isHidden: false + }) + .then(() => updateResult("connectToProtectedWifiSSID", "Connected to " + ssid)) + .catch((err: any) => updateResult("connectToProtectedWifiSSID", "Error: " + safeStringify(err))); + }} + /> + + + + + + + { + WifiManager.suggestWifiNetwork([{ + ssid: ssid, + password: password, + isWpa3: false, + isAppInteractionRequired: false + }]) + .then((res: any) => updateResult("suggestWifiNetwork", "Result: " + safeStringify(res))) + .catch((err: any) => updateResult("suggestWifiNetwork", "Error: " + safeStringify(err))); + }} + /> + + + + + + + + + + { + WifiManager.getCurrentWifiSSID() + .then((ssid: any) => updateResult("getCurrentWifiSSID", "Current SSID: " + safeStringify(ssid))) + .catch((err: any) => updateResult("getCurrentWifiSSID", "Error: " + safeStringify(err))); + }} + /> + + + + + + + { + WifiManager.getBSSID() + .then((bssid: any) => updateResult("getBSSID", "BSSID: " + safeStringify(bssid))) + .catch((err: any) => updateResult("getBSSID", "Error: " + safeStringify(err))); + }} + /> + + + + + + + { + WifiManager.getIP() + .then((ip: any) => updateResult("getIP", "IP: " + safeStringify(ip))) + .catch((err: any) => updateResult("getIP", "Error: " + safeStringify(err))); + }} + /> + + + + + + + { + WifiManager.getFrequency() + .then((freq: any) => updateResult("getFrequency", "Frequency: " + safeStringify(freq))) + .catch((err: any) => updateResult("getFrequency", "Error: " + safeStringify(err))); + }} + /> + + + + + + + { + WifiManager.getCurrentSignalStrength() + .then((level: any) => updateResult("getCurrentSignalStrength", "Signal Strength: " + safeStringify(level))) + .catch((err: any) => updateResult("getCurrentSignalStrength", "Error: " + safeStringify(err))); + }} + /> + + + + + + + { + WifiManager.connectionStatus() + .then((status: any) => updateResult("connectionStatus", "Connected: " + safeStringify(status))) + .catch((err: any) => updateResult("connectionStatus", "Error: " + safeStringify(err))); + }} + /> + + + + + + + { + WifiManager.isEnabled() + .then((enabled: any) => updateResult("isEnabled", "Wifi Enabled: " + safeStringify(enabled))) + .catch((err: any) => updateResult("isEnabled", "Error: " + safeStringify(err))); + }} + /> + + + + + + + + + + { + try { + WifiManager.setEnabled(true); + updateResult("setEnabledTrue", "Request to enable Wifi sent"); + } catch (err) { + updateResult("setEnabledTrue", "Error: " + safeStringify(err)); + } + }} + /> + + + + + + + { + try { + WifiManager.setEnabled(false); + updateResult("setEnabledFalse", "Request to disable Wifi sent"); + } catch (err) { + updateResult("setEnabledFalse", "Error: " + safeStringify(err)); + } + }} + /> + + + + + + + { + WifiManager.disconnect() + .then((res: any) => updateResult("disconnect", "Disconnect: " + safeStringify(res))) + .catch((err: any) => updateResult("disconnect", "Error: " + safeStringify(err))); + }} + /> + + + + + + + { + WifiManager.isRemoveWifiNetwork(ssid) + .then((res: any) => updateResult("isRemoveWifiNetwork", "Remove Network: " + safeStringify(res))) + .catch((err: any) => updateResult("isRemoveWifiNetwork", "Error: " + safeStringify(err))); + }} + /> + + + + + + + { + WifiManager.forceWifiUsageWithOptions(true, { noInternet: true }) + .then(() => updateResult("forceWifiUsageWithOptions", "Force Wifi Enabled")) + .catch((err: any) => updateResult("forceWifiUsageWithOptions", "Error: " + safeStringify(err))); + }} + /> + + + + + + + { + WifiManager.forceWifiUsage(true) + .then(() => updateResult("forceWifiUsage", "Force Wifi Enabled")) + .catch((err: any) => updateResult("forceWifiUsage", "Error: " + safeStringify(err))); + }} + /> + + + + + + + + + + { + WifiManager.connectToSSID(ssid) + .then(() => updateResult("connectToSSID", "Connected")) + .catch((err: any) => updateResult("connectToSSID", "Error: " + safeStringify(err))); + }} + /> + + + + + + + { + WifiManager.connectToSSIDPrefix(ssid) + .then(() => updateResult("connectToSSIDPrefix", "Connected")) + .catch((err: any) => updateResult("connectToSSIDPrefix", "Error: " + safeStringify(err))); + }} + /> + + + + + + + { + WifiManager.disconnectFromSSID(ssid) + .then(() => updateResult("disconnectFromSSID", "Disconnected")) + .catch((err: any) => updateResult("disconnectFromSSID", "Error: " + safeStringify(err))); + }} + /> + + + + + + + { + WifiManager.connectToProtectedSSIDOnce(ssid, password, false, true) + .then(() => updateResult("connectToProtectedSSIDOnce", "Connected")) + .catch((err: any) => updateResult("connectToProtectedSSIDOnce", "Error: " + safeStringify(err))); + }} + /> + + + + + + + { + WifiManager.connectToProtectedSSIDPrefix(ssid, password, false) + .then(() => updateResult("connectToProtectedSSIDPrefix", "Connected")) + .catch((err: any) => updateResult("connectToProtectedSSIDPrefix", "Error: " + safeStringify(err))); + }} + /> + + + + + + + { + WifiManager.connectToProtectedSSIDPrefixOnce(ssid, password, false, true) + .then(() => updateResult("connectToProtectedSSIDPrefixOnce", "Connected")) + .catch((err: any) => updateResult("connectToProtectedSSIDPrefixOnce", "Error: " + safeStringify(err))); + }} + /> + + + + + + + ); +}; + +const styles = StyleSheet.create({ + headerContainer: { + backgroundColor: COLORS.background, + padding: 10, + borderBottomWidth: 1, + borderBottomColor: COLORS.border, + elevation: 2, + zIndex: 100, + }, + headerTitle: { + fontSize: 20, + fontWeight: 'bold', + color: COLORS.text, + marginBottom: 10, + textAlign: 'center', + }, + inputCard: { + backgroundColor: COLORS.card, + borderRadius: 10, + padding: 10, + shadowColor: '#000', + shadowOffset: { width: 0, height: 2 }, + shadowOpacity: 0.1, + shadowRadius: 4, + elevation: 3, + }, + input: { + height: 44, + borderColor: COLORS.border, + borderWidth: 1, + borderRadius: 8, + marginBottom: 10, + paddingHorizontal: 12, + backgroundColor: '#FAFAFA', + fontSize: 16, + color: COLORS.text, + }, + testCaseContent: { + padding: 10, + }, + button: { + paddingVertical: 12, + paddingHorizontal: 20, + borderRadius: 8, + alignItems: 'center', + justifyContent: 'center', + elevation: 2, + shadowColor: '#000', + shadowOffset: { width: 0, height: 1 }, + shadowOpacity: 0.2, + shadowRadius: 2, + }, + buttonText: { + color: 'white', + fontSize: 16, + fontWeight: '600', + }, + resultContainer: { + marginTop: 10, + padding: 10, + backgroundColor: '#F8F9FA', + borderRadius: 6, + borderLeftWidth: 4, + borderLeftColor: COLORS.secondary, + }, + resultLabel: { + fontSize: 12, + color: COLORS.subText, + marginBottom: 4, + fontWeight: '600', + }, + resultText: { + fontSize: 14, + color: COLORS.text, + fontFamily: 'monospace', + }, + descriptionText: { + fontSize: 13, + color: '#666', + marginBottom: 10, + lineHeight: 18, + fontStyle: 'italic', + }, + wifiListContainer: { + padding: 10, + backgroundColor: COLORS.background, + }, + sectionTitle: { + fontSize: 18, + fontWeight: 'bold', + color: COLORS.text, + marginBottom: 10, + marginLeft: 5, + }, + wifiItem: { + padding: 15, + backgroundColor: COLORS.card, + borderRadius: 10, + marginBottom: 8, + shadowColor: '#000', + shadowOffset: { width: 0, height: 1 }, + shadowOpacity: 0.1, + shadowRadius: 2, + elevation: 2, + }, + wifiItemHeader: { + flexDirection: 'row', + justifyContent: 'space-between', + alignItems: 'center', + marginBottom: 4, + }, + wifiSSID: { + fontSize: 16, + fontWeight: 'bold', + color: COLORS.text, + }, + wifiLevel: { + fontSize: 14, + color: COLORS.success, + fontWeight: '600', + }, + wifiBSSID: { + fontSize: 12, + color: COLORS.subText, + marginBottom: 2, + }, + wifiDetails: { + fontSize: 11, + color: COLORS.subText, + fontStyle: 'italic', + }, +}); + + +``` +## Link + +This step provides guidance for manually configuring native dependencies. + +First, use DevEco Studio to open the HarmonyOS project `harmony` in your project. + +### 1. Add the `overrides` field to the `oh-package.json` file in the root directory of the project. + +```json +{ + ... + "overrides": { + "@rnoh/react-native-openharmony" : "./react_native_openharmony" + } + ... +} +``` + +### 2. Introduce Native Code + +Currently, there are two methods: + +1. Import via har package (this method will be deprecated after the IDE improves related features; currently, it is the preferred method); +2. Directly link the source code. + +**Method 1: Import via har package (Recommended)** + +> [!TIP] The har package is located in the `harmony` folder under the third-party library installation path. + +Open `entry/oh-package.json5` and add the following dependencies. + +```json +"dependencies": { + "@rnoh/react-native-openharmony": "file:../react_native_openharmony", + "@react-native-ohos/react-native-wifi-reborn": "file:../../node_modules/@react-native-ohos/react-native-wifi-reborn/harmony/wifi_reborn.har" + } +``` + +Click the `sync` button in the top right corner + +Or execute in the terminal: + +```bash +cd entry +ohpm install +``` + +Method 2: Directly link the source code + +> [!TIP] If you need to use direct source code linking, refer to [Direct Source Code Linking Instructions](/zh-cn/link-source-code.md) + + +### 4. Configure CMakeLists and introduce turbo_log + +Open `entry/src/main/cpp/CMakeLists.txt` and add: + +```diff +include(FetchContent) +# BOOST +set(BOOST_ENABLE_CMAKE On) +FetchContent_Declare( + Boost + URL /7277/boost-1.82.0.tar.xz + OVERRIDE_FIND_PACKAGE) +project(rnapp) +cmake_minimum_required(VERSION 3.4.1) +set(CMAKE_SKIP_BUILD_RPATH TRUE) +set(RNOH_APP_DIR "${CMAKE_CURRENT_SOURCE_DIR}") +set(NODE_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../node_modules") ++ set(OH_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/../../../oh_modules") +set(RNOH_CPP_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../../oh_modules/@rnoh/react-native-openharmony/src/main/cpp") +set(RNOH_GENERATED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/generated") +set(LOG_VERBOSITY_LEVEL 1) +set(CMAKE_ASM_FLAGS "-Wno-error=unused-command-line-argument -Qunused-arguments") +set(CMAKE_CXX_FLAGS "-fstack-protector-strong -Wl,-z,relro,-z,now,-z,noexecstack -s -fPIE -pie") +set(WITH_HITRACE_SYSTRACE 1) # for other CMakeLists.txt files to use +add_compile_definitions(WITH_HITRACE_SYSTRACE) + + +add_subdirectory("${RNOH_CPP_DIR}" ./rn) + +# RNOH_BEGIN: manual_package_linking_1 +add_subdirectory("${OH_MODULES}/@react-native-ohos/react-native-gesture-handler/src/main/cpp" ./gesture-handler) ++ add_subdirectory("${OH_MODULES}/@react-native-ohos/react-native-wifi-reborn/src/main/cpp" ./wifi_reborn) +# RNOH_END: manual_package_linking_1 + +file(GLOB GENERATED_CPP_FILES "./generated/*.cpp") # this line is needed by codegen v1 +add_library(rnoh_app SHARED + ${GENERATED_CPP_FILES} + "./PackageProvider.cpp" + "${RNOH_CPP_DIR}/RNOHAppNapiBridge.cpp" +) +target_link_libraries(rnoh_app PUBLIC rnoh) + +# RNOH_BEGIN: manual_package_linking_2 +target_link_libraries(rnoh_app PUBLIC rnoh_gesture_handler) ++ target_link_libraries(rnoh_app PUBLIC rnoh_wifi_reborn) +# RNOH_END: manual_package_linking_2 + +``` + +### 4.Import the TurboLogPackage on the ArkTS side + +打开 `entry/src/main/cpp/PackageProvider.cpp`,添加: + +```diff +#include "RNOH/PackageProvider.h" +#include "generated/RNOHGeneratedPackage.h" +#include "SamplePackage.h" ++ #include "WifiRebornPackage.h" + +using namespace rnoh; + +std::vector> PackageProvider::getPackages(Package::Context ctx) { + return { + std::make_shared(ctx), + std::make_shared(ctx), ++ std::make_shared(ctx), + }; +} +``` + +### 5. Run + +Click the `sync` button in the top right corner. + +Or execute the following in the terminal: + +```bash +cd entry +ohpm install +``` + +Then compile and run. + +## Constraints and Limitations + +### Compatibility + +The content of this document has been verified with the following versions: +1. RNOH: 0.72.90; SDK: HarmonyOS NEXT Developer DB3; IDE: DevEco Studio: 5.0.5.220; ROM: NEXT.0.0.105; +2. RNOH: 0.77.18; SDK: HarmonyOS 6.0.0 Release; IDE: DevEco Studio 6.0.0.858; ROM: 6.0.0.112; + +### Permission requirements +Among the following permissions, there is a 'system_masic' permission, while the default application permission is' normal ', which can only be used at the' normal 'level. Therefore, when installing the HAP package, an error may occur * * 9568289 * *, please refer to the [document]( https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/bm-tool-V5#ZH -CN_TOPIC_0000001884757326__%E5%AE%89%E8%A3%85hap%E6%97%B6%E6%8F%90%E7%A4%BAcode9568289-error-install-failed-due-to-grant-request-permissions-failed) Change the application level to 'system_masic'` + +#### Add permissions to module.json5 in the entry directory + +Open 'entry/src/main/module. json5' and add: + +```diff +... +"requestPermissions": [ + { + "name": "ohos.permission.GET_WIFI_INFO", + "reason": "$string:wifi_info_reason", + "usedScene": { + "abilities": [], + "when": "inuse" + } + }, + { + "name": "ohos.permission.SET_WIFI_INFO", + "reason": "$string:wifi_set_reason", + "usedScene": { + "abilities": [], + "when": "inuse" + } + }, + { + "name": "ohos.permission.LOCATION", + "reason": "$string:location_reason", + "usedScene": { + "abilities": [], + "when": "inuse" + } + }, + { + "name": "ohos.permission.APPROXIMATELY_LOCATION", + "reason": "$string:location_approx_reason", + "usedScene": { + "abilities": [], + "when": "inuse" + } + } + ], +``` + +#### Add the reason for applying for the above permissions in the entry directory + +Open 'entry/src/main/resources/base/element/string. json' and add: + +```diff +... +{ + "string": [ + { + "name": "wifi_info_reason", + "value": "需要获取WiFi信息以显示当前连接的网络状态" + }, + { + "name": "wifi_set_reason", + "value": "需要配置WiFi网络以连接到指定的无线网络" + }, + { + "name": "wifi_manage_reason", + "value": "需要管理WiFi连接以提供完整的网络控制功能" + }, + { + "name": "wifi_mac_reason", + "value": "需要获取WiFi MAC地址用于网络识别" + }, + { + "name": "location_reason", + "value": "需要位置权限以扫描附近的WiFi网络(系统要求)" + }, + { + "name": "location_approx_reason", + "value": "需要大致位置权限以扫描WiFi网络" + }, + { + "name": "module_desc", + "value": "React Native WiFi Manager - WiFi网络管理模块" + } + ] +} + +``` + +## Attributes + +> [!TIP] The "Platform" column indicates the platforms supported by the original third-party library. + +> [!TIP] The "HarmonyOS Support" column shows "yes" if the attribute is supported on the HarmonyOS platform, "no" if not supported, and "partially" if partially supported. The usage method is consistent across platforms, and the effect aligns with that of iOS or Android. + +**wifi-reborn**:A third-party library for WiFi management in React Native, mainly used to implement various operations related to device WiFi functionality in applications. + +| Name | Description | Type | Required | Platform | HarmonyOS Support | +|-----------------|----------------------|----------|----------|-------------|-------------------| +| connectToProtectSSID | Connect to a protected SSID | function | no | Android/IOS | yes | +| suggestWifiNetwork | Recommend/prompt the specified visible WIFI network to the mobile device system | function | no | Android/IOS | yes | +| connectToProtectedWifiSSID | Connect to the protected WIFI named SSID | function | no | Android/IOS | yes | +| getCurrentWifiSSID | Return the SSID of the current WiFi network | function | no | Android/IOS | yes | +| connectToSSID | Connect to SSID | function | no | IOS | yes | +| connectToSSIDPrefix | Connect to SSID with a specific prefix | function | no | IOS | yes | +| disconnectFromSSID | Disconnect from SSID | function | no | IOS | yes | +| connectToProtectedSSIDOnce | Connect to the protected SSID once | function | no | IOS | no | +| connectToProtectedSSIDPrefix | Connect to a protected SSID with a specific prefix | function | no | IOS | yes | +| connectToProtectedSSIDPrefixOnce | Connect to a protected SSID with a specific prefix once | function | no | IOS | no | +| loadWifiList | Return to the list of nearby WIFI networks | function | no | Android | yes | +| reScanAndLoadWifiList | Rescan visible WiFi networks in the surrounding area and load and return the complete WiFi list data | function | no | Android | yes | +| isEnabled | Check if WIFI is turned on | function | no | Android | yes | +| setEnabled | Set WIFI on or off on the device | function | no | Android | yes | +| connectionStatus | The current device is connected to WIFI and has been connected, returning true | function | no | Android | yes | +| disconnect | Disconnect the current WIFI connection | function | no | Android | yes | +| getBSSID | Return the BSSID of the current WIFI connection | function | no | Android | yes | +| getCurrentSignalStrength | Return the RSSI (signal strength) of the current WIFI connection | function | no | Android | yes | +| getFrequency | Return the signal frequency of the currently connected WIFI | function | no | Android | yes | +| getIP | Return the IP address of the current WIFI connection | function | no | Android | yes | +| isRemoveWifiNetwork | Remove the specified WiFi network with saved configuration from the device | function | no | Android | yes | +| forceWifiUsage | Force the current application's network requests to go through the WIFI channel that the device is already connected to, ignoring mobile data | function | no | Android | yes | +| forceWifiUsageWithOptions | Force the current application's network requests to go through the WIFI channel that the device is already connected to, ignoring mobile data (which can be passed into the configuration object) | function | no | Android | yes | + + +## Static method + +## outstanding issues + +## other + + +## open source license + + +This project is based on [The MIT License (MIT)]( https://github.com/JuanSeBestia/react-native-wifi-reborn/blob/master/LICENSE )Please enjoy and participate freely in open source. + diff --git a/zh-cn/react-native-wifi-reborn.md b/zh-cn/react-native-wifi-reborn.md new file mode 100644 index 00000000..34cdbff4 --- /dev/null +++ b/zh-cn/react-native-wifi-reborn.md @@ -0,0 +1,967 @@ +> 模板版本:v0.2.2 + +

+

react-native-wifi-reborn

+

+ +请到三方库的 Releases 发布地址查看配套的版本信息: + +| 三方库版本 | 发布信息 | 支持RN版本 | +| ---------- | ------------------------------------------------------------ | ---------- | +| 0.6.1 | [@react-native-ohos/react-native-wifi-reborn Releases](https://github.com/react-native-oh-library/react-native-wifi-reborn/releases) | 0.72 | +| 0.7.0 | [@react-native-ohos/react-native-wifi-reborn Releases](https://github.com/react-native-oh-library/react-native-wifi-reborn/releases) | 0.77 | + +> [!TIP] [Github 地址](https://github.com/react-native-oh-library/react-native-wifi-reborn) + +## 安装与使用 + +进入到工程目录并输入以下命令: + + + + +#### npm + +```bash +npm install @react-native-ohos/react-native-wifi-reborn +``` + +#### yarn + +```bash +yarn add @react-native-ohos/react-native-wifi-reborn +``` + + + +下面的代码展示了这个库的基本使用场景: + +> [!WARNING] 使用时 import 的库名不变。 +### wifi-reborn example +``` js +import React, { useState } from 'react'; +import { ScrollView, StyleSheet, Text, TouchableOpacity, View, TextInput, Alert } from 'react-native'; +import { Tester, TestSuite, TestCase } from '@rnoh/testerino'; +import WifiManager from 'react-native-wifi-reborn'; +import RTNPermissions, { Permission } from "react-native-permissions"; + +const permissionNormal: Permission[] = [ + 'ohos.permission.GET_WIFI_INFO', + 'ohos.permission.SET_WIFI_INFO', + 'ohos.permission.LOCATION', + 'ohos.permission.MANAGE_WIFI_CONNECTION', + 'ohos.permission.GET_WIFI_LOCAL_MAC', + 'ohos.permission.APPROXIMATELY_LOCATION', +]; + +const COLORS = { + primary: '#007AFF', + secondary: '#5856D6', + success: '#4CD964', + background: '#F2F2F7', + card: '#FFFFFF', + text: '#000000', + subText: '#8E8E93', + border: '#C7C7CC', + error: '#FF3B30', +}; + +const CustomButton = ({ title, onPress, color = COLORS.primary }: { title: string, onPress: () => void, color?: string }) => ( + + {title} + +); + +const ResultArea = ({ text }: { text: string }) => { + if (!text) return null; + return ( + + Result: + {text} + + ); +}; + +const Description = ({ text }: { text: string }) => ( + {text} +); + +export const TurboLogDemoTest = () => { + const [wifiList, setWifiList] = useState([]); + const [ssid, setSsid] = useState(''); + const [password, setPassword] = useState(''); + const [log, setLog] = useState(''); + const [results, setResults] = useState<{ [key: string]: string }>({}); + + const addLog = (msg: string) => { + console.info(msg); + setLog(prev => msg + '\n' + prev); + }; + + const updateResult = (key: string, value: string) => { + setResults(prev => ({ ...prev, [key]: value })); + addLog(`${key}: ${value}`); + }; + + const safeStringify = (val: any) => { + if (typeof val === 'string') return val; + try { + return JSON.stringify(val, null, 2); + } catch (e) { + return String(val); + } + }; + + return ( + + + + Wifi Manager Demo + + + + + + + + + + + { + try { + let requestMultiple = await RTNPermissions.requestMultiple(permissionNormal); + updateResult("Permissions", safeStringify(requestMultiple)); + } catch (e) { + updateResult("Permissions", "Error: " + safeStringify(e)); + } + }} + /> + + + + + + + + + + { + WifiManager.loadWifiList().then((list: any) => { + updateResult("loadWifiList", "Loaded " + list.length + " networks"); + setWifiList(list); + }).catch((err: any) => updateResult("loadWifiList", "Error: " + safeStringify(err))); + }} + /> + + + + + + + { + WifiManager.reScanAndLoadWifiList().then((list: any) => { + updateResult("reScanAndLoadWifiList", "Loaded " + list.length + " networks"); + setWifiList(list); + }).catch((err: any) => updateResult("reScanAndLoadWifiList", "Error: " + safeStringify(err))); + }} + /> + + + + {wifiList.length > 0 && ( + + Available Networks + {wifiList.map((item, index) => ( + { + setSsid(item.SSID); + addLog("Selected SSID: " + item.SSID); + }} + > + + {item.SSID || ''} + {item.level} dBm + + {item.BSSID} + {item.capabilities} + + ))} + + )} + + + + + + + { + addLog(`Connecting to ${ssid}...`); + WifiManager.connectToProtectedSSID(ssid, password, false, false) + .then(() => updateResult("connectToProtectedSSID", "Connected to " + ssid)) + .catch((err: any) => updateResult("connectToProtectedSSID", "Error: " + safeStringify(err))); + }} + /> + + + + + + + { + addLog(`Connecting to ${ssid} with options...`); + WifiManager.connectToProtectedWifiSSID({ + ssid: ssid, + password: password, + isWEP: false, + isHidden: false + }) + .then(() => updateResult("connectToProtectedWifiSSID", "Connected to " + ssid)) + .catch((err: any) => updateResult("connectToProtectedWifiSSID", "Error: " + safeStringify(err))); + }} + /> + + + + + + + { + WifiManager.suggestWifiNetwork([{ + ssid: ssid, + password: password, + isWpa3: false, + isAppInteractionRequired: false + }]) + .then((res: any) => updateResult("suggestWifiNetwork", "Result: " + safeStringify(res))) + .catch((err: any) => updateResult("suggestWifiNetwork", "Error: " + safeStringify(err))); + }} + /> + + + + + + + + + + { + WifiManager.getCurrentWifiSSID() + .then((ssid: any) => updateResult("getCurrentWifiSSID", "Current SSID: " + safeStringify(ssid))) + .catch((err: any) => updateResult("getCurrentWifiSSID", "Error: " + safeStringify(err))); + }} + /> + + + + + + + { + WifiManager.getBSSID() + .then((bssid: any) => updateResult("getBSSID", "BSSID: " + safeStringify(bssid))) + .catch((err: any) => updateResult("getBSSID", "Error: " + safeStringify(err))); + }} + /> + + + + + + + { + WifiManager.getIP() + .then((ip: any) => updateResult("getIP", "IP: " + safeStringify(ip))) + .catch((err: any) => updateResult("getIP", "Error: " + safeStringify(err))); + }} + /> + + + + + + + { + WifiManager.getFrequency() + .then((freq: any) => updateResult("getFrequency", "Frequency: " + safeStringify(freq))) + .catch((err: any) => updateResult("getFrequency", "Error: " + safeStringify(err))); + }} + /> + + + + + + + { + WifiManager.getCurrentSignalStrength() + .then((level: any) => updateResult("getCurrentSignalStrength", "Signal Strength: " + safeStringify(level))) + .catch((err: any) => updateResult("getCurrentSignalStrength", "Error: " + safeStringify(err))); + }} + /> + + + + + + + { + WifiManager.connectionStatus() + .then((status: any) => updateResult("connectionStatus", "Connected: " + safeStringify(status))) + .catch((err: any) => updateResult("connectionStatus", "Error: " + safeStringify(err))); + }} + /> + + + + + + + { + WifiManager.isEnabled() + .then((enabled: any) => updateResult("isEnabled", "Wifi Enabled: " + safeStringify(enabled))) + .catch((err: any) => updateResult("isEnabled", "Error: " + safeStringify(err))); + }} + /> + + + + + + + + + + { + try { + WifiManager.setEnabled(true); + updateResult("setEnabledTrue", "Request to enable Wifi sent"); + } catch (err) { + updateResult("setEnabledTrue", "Error: " + safeStringify(err)); + } + }} + /> + + + + + + + { + try { + WifiManager.setEnabled(false); + updateResult("setEnabledFalse", "Request to disable Wifi sent"); + } catch (err) { + updateResult("setEnabledFalse", "Error: " + safeStringify(err)); + } + }} + /> + + + + + + + { + WifiManager.disconnect() + .then((res: any) => updateResult("disconnect", "Disconnect: " + safeStringify(res))) + .catch((err: any) => updateResult("disconnect", "Error: " + safeStringify(err))); + }} + /> + + + + + + + { + WifiManager.isRemoveWifiNetwork(ssid) + .then((res: any) => updateResult("isRemoveWifiNetwork", "Remove Network: " + safeStringify(res))) + .catch((err: any) => updateResult("isRemoveWifiNetwork", "Error: " + safeStringify(err))); + }} + /> + + + + + + + { + WifiManager.forceWifiUsageWithOptions(true, { noInternet: true }) + .then(() => updateResult("forceWifiUsageWithOptions", "Force Wifi Enabled")) + .catch((err: any) => updateResult("forceWifiUsageWithOptions", "Error: " + safeStringify(err))); + }} + /> + + + + + + + { + WifiManager.forceWifiUsage(true) + .then(() => updateResult("forceWifiUsage", "Force Wifi Enabled")) + .catch((err: any) => updateResult("forceWifiUsage", "Error: " + safeStringify(err))); + }} + /> + + + + + + + + + + { + WifiManager.connectToSSID(ssid) + .then(() => updateResult("connectToSSID", "Connected")) + .catch((err: any) => updateResult("connectToSSID", "Error: " + safeStringify(err))); + }} + /> + + + + + + + { + WifiManager.connectToSSIDPrefix(ssid) + .then(() => updateResult("connectToSSIDPrefix", "Connected")) + .catch((err: any) => updateResult("connectToSSIDPrefix", "Error: " + safeStringify(err))); + }} + /> + + + + + + + { + WifiManager.disconnectFromSSID(ssid) + .then(() => updateResult("disconnectFromSSID", "Disconnected")) + .catch((err: any) => updateResult("disconnectFromSSID", "Error: " + safeStringify(err))); + }} + /> + + + + + + + { + WifiManager.connectToProtectedSSIDOnce(ssid, password, false, true) + .then(() => updateResult("connectToProtectedSSIDOnce", "Connected")) + .catch((err: any) => updateResult("connectToProtectedSSIDOnce", "Error: " + safeStringify(err))); + }} + /> + + + + + + + { + WifiManager.connectToProtectedSSIDPrefix(ssid, password, false) + .then(() => updateResult("connectToProtectedSSIDPrefix", "Connected")) + .catch((err: any) => updateResult("connectToProtectedSSIDPrefix", "Error: " + safeStringify(err))); + }} + /> + + + + + + + { + WifiManager.connectToProtectedSSIDPrefixOnce(ssid, password, false, true) + .then(() => updateResult("connectToProtectedSSIDPrefixOnce", "Connected")) + .catch((err: any) => updateResult("connectToProtectedSSIDPrefixOnce", "Error: " + safeStringify(err))); + }} + /> + + + + + + + ); +}; + +const styles = StyleSheet.create({ + headerContainer: { + backgroundColor: COLORS.background, + padding: 10, + borderBottomWidth: 1, + borderBottomColor: COLORS.border, + elevation: 2, + zIndex: 100, + }, + headerTitle: { + fontSize: 20, + fontWeight: 'bold', + color: COLORS.text, + marginBottom: 10, + textAlign: 'center', + }, + inputCard: { + backgroundColor: COLORS.card, + borderRadius: 10, + padding: 10, + shadowColor: '#000', + shadowOffset: { width: 0, height: 2 }, + shadowOpacity: 0.1, + shadowRadius: 4, + elevation: 3, + }, + input: { + height: 44, + borderColor: COLORS.border, + borderWidth: 1, + borderRadius: 8, + marginBottom: 10, + paddingHorizontal: 12, + backgroundColor: '#FAFAFA', + fontSize: 16, + color: COLORS.text, + }, + testCaseContent: { + padding: 10, + }, + button: { + paddingVertical: 12, + paddingHorizontal: 20, + borderRadius: 8, + alignItems: 'center', + justifyContent: 'center', + elevation: 2, + shadowColor: '#000', + shadowOffset: { width: 0, height: 1 }, + shadowOpacity: 0.2, + shadowRadius: 2, + }, + buttonText: { + color: 'white', + fontSize: 16, + fontWeight: '600', + }, + resultContainer: { + marginTop: 10, + padding: 10, + backgroundColor: '#F8F9FA', + borderRadius: 6, + borderLeftWidth: 4, + borderLeftColor: COLORS.secondary, + }, + resultLabel: { + fontSize: 12, + color: COLORS.subText, + marginBottom: 4, + fontWeight: '600', + }, + resultText: { + fontSize: 14, + color: COLORS.text, + fontFamily: 'monospace', + }, + descriptionText: { + fontSize: 13, + color: '#666', + marginBottom: 10, + lineHeight: 18, + fontStyle: 'italic', + }, + wifiListContainer: { + padding: 10, + backgroundColor: COLORS.background, + }, + sectionTitle: { + fontSize: 18, + fontWeight: 'bold', + color: COLORS.text, + marginBottom: 10, + marginLeft: 5, + }, + wifiItem: { + padding: 15, + backgroundColor: COLORS.card, + borderRadius: 10, + marginBottom: 8, + shadowColor: '#000', + shadowOffset: { width: 0, height: 1 }, + shadowOpacity: 0.1, + shadowRadius: 2, + elevation: 2, + }, + wifiItemHeader: { + flexDirection: 'row', + justifyContent: 'space-between', + alignItems: 'center', + marginBottom: 4, + }, + wifiSSID: { + fontSize: 16, + fontWeight: 'bold', + color: COLORS.text, + }, + wifiLevel: { + fontSize: 14, + color: COLORS.success, + fontWeight: '600', + }, + wifiBSSID: { + fontSize: 12, + color: COLORS.subText, + marginBottom: 2, + }, + wifiDetails: { + fontSize: 11, + color: COLORS.subText, + fontStyle: 'italic', + }, +}); + + +``` +## Link + +此步骤为手动配置原生依赖项的指导。 + +首先需要使用 DevEco Studio 打开项目里的 HarmonyOS 工程 `harmony` + +### 1.在工程根目录的 `oh-package.json` 添加 overrides字段 + +```json +{ + ... + "overrides": { + "@rnoh/react-native-openharmony" : "./react_native_openharmony" + } + ... +} +``` + +### 2.引入原生端代码 + +目前有两种方法: + +1. 通过 har 包引入(在 IDE 完善相关功能后该方法会被遗弃,目前首选此方法); +2. 直接链接源码。 + +方法一:通过 har 包引入 (推荐) + +> [!TIP] har 包位于三方库安装路径的 `harmony` 文件夹下。 + +打开 `entry/oh-package.json5`,添加以下依赖 + +```json +"dependencies": { + "@rnoh/react-native-openharmony": "file:../react_native_openharmony", + "@react-native-ohos/react-native-wifi-reborn": "file:../../node_modules/@react-native-ohos/react-native-wifi-reborn/harmony/wifi_reborn.har" + } +``` + +点击右上角的 `sync` 按钮 + +或者在终端执行: + +```bash +cd entry +ohpm install +``` + +方法二:直接链接源码 + +> [!TIP] 如需使用直接链接源码,请参考[直接链接源码说明](/zh-cn/link-source-code.md) + + +### 4.配置 CMakeLists 和引入 turbo_log + +打开 entry/src/main/cpp/CMakeLists.txt,添加: + +```diff +include(FetchContent) +# BOOST +set(BOOST_ENABLE_CMAKE On) +FetchContent_Declare( + Boost + URL /7277/boost-1.82.0.tar.xz + OVERRIDE_FIND_PACKAGE) +project(rnapp) +cmake_minimum_required(VERSION 3.4.1) +set(CMAKE_SKIP_BUILD_RPATH TRUE) +set(RNOH_APP_DIR "${CMAKE_CURRENT_SOURCE_DIR}") +set(NODE_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../node_modules") ++ set(OH_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/../../../oh_modules") +set(RNOH_CPP_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../../oh_modules/@rnoh/react-native-openharmony/src/main/cpp") +set(RNOH_GENERATED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/generated") +set(LOG_VERBOSITY_LEVEL 1) +set(CMAKE_ASM_FLAGS "-Wno-error=unused-command-line-argument -Qunused-arguments") +set(CMAKE_CXX_FLAGS "-fstack-protector-strong -Wl,-z,relro,-z,now,-z,noexecstack -s -fPIE -pie") +set(WITH_HITRACE_SYSTRACE 1) # for other CMakeLists.txt files to use +add_compile_definitions(WITH_HITRACE_SYSTRACE) + + +add_subdirectory("${RNOH_CPP_DIR}" ./rn) + +# RNOH_BEGIN: manual_package_linking_1 +add_subdirectory("${OH_MODULES}/@react-native-ohos/react-native-gesture-handler/src/main/cpp" ./gesture-handler) ++ add_subdirectory("${OH_MODULES}/@react-native-ohos/react-native-wifi-reborn/src/main/cpp" ./wifi_reborn) +# RNOH_END: manual_package_linking_1 + +file(GLOB GENERATED_CPP_FILES "./generated/*.cpp") # this line is needed by codegen v1 +add_library(rnoh_app SHARED + ${GENERATED_CPP_FILES} + "./PackageProvider.cpp" + "${RNOH_CPP_DIR}/RNOHAppNapiBridge.cpp" +) +target_link_libraries(rnoh_app PUBLIC rnoh) + +# RNOH_BEGIN: manual_package_linking_2 +target_link_libraries(rnoh_app PUBLIC rnoh_gesture_handler) ++ target_link_libraries(rnoh_app PUBLIC rnoh_wifi_reborn) +# RNOH_END: manual_package_linking_2 + +``` + +### 4.Import the TurboLogPackage on the ArkTS side + +打开 `entry/src/main/cpp/PackageProvider.cpp`,添加: + +```diff +#include "RNOH/PackageProvider.h" +#include "generated/RNOHGeneratedPackage.h" +#include "SamplePackage.h" ++ #include "WifiRebornPackage.h" + +using namespace rnoh; + +std::vector> PackageProvider::getPackages(Package::Context ctx) { + return { + std::make_shared(ctx), + std::make_shared(ctx), ++ std::make_shared(ctx), + }; +} +``` + +### 5.运行 + +点击右上角的 `sync` 按钮 + +或者在终端执行: + +```bash +cd entry +ohpm install +``` + +然后编译、运行即可。 + +## 约束与限制 + +### 兼容性 + +本文档内容基于以下版本验证通过: +1. RNOH:0.72.90; SDK:HarmonyOS NEXT Developer DB3; IDE: DevEco Studio: 5.0.5.220; ROM:NEXT.0.0.105; +2. RNOH:0.77.18; SDK:HarmonyOS 6.0.0 Release; IDE: DevEco Studio 6.0.0.858; ROM:6.0.0.112; + +### 权限要求 + +以下权限中有`system_basic` 权限,而默认的应用权限是 `normal` ,只能使用 `normal` 等级的权限,所以可能会在安装hap包时报错**9568289**,请参考 [文档](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/bm-tool-V5#ZH-CN_TOPIC_0000001884757326__%E5%AE%89%E8%A3%85hap%E6%97%B6%E6%8F%90%E7%A4%BAcode9568289-error-install-failed-due-to-grant-request-permissions-failed) 修改应用等级为 `system_basic` + +#### 在 entry 目录下的module.json5中添加权限 + +打开 `entry/src/main/module.json5`,添加: + +```diff +... +"requestPermissions": [ + { + "name": "ohos.permission.GET_WIFI_INFO", + "reason": "$string:wifi_info_reason", + "usedScene": { + "abilities": [], + "when": "inuse" + } + }, + { + "name": "ohos.permission.SET_WIFI_INFO", + "reason": "$string:wifi_set_reason", + "usedScene": { + "abilities": [], + "when": "inuse" + } + }, + { + "name": "ohos.permission.LOCATION", + "reason": "$string:location_reason", + "usedScene": { + "abilities": [], + "when": "inuse" + } + }, + { + "name": "ohos.permission.APPROXIMATELY_LOCATION", + "reason": "$string:location_approx_reason", + "usedScene": { + "abilities": [], + "when": "inuse" + } + } + ], +``` + +#### 在 entry 目录下添加申请以上权限的原因 + +打开 `entry/src/main/resources/base/element/string.json`,添加: + +```diff +... +{ + "string": [ + { + "name": "wifi_info_reason", + "value": "需要获取WiFi信息以显示当前连接的网络状态" + }, + { + "name": "wifi_set_reason", + "value": "需要配置WiFi网络以连接到指定的无线网络" + }, + { + "name": "wifi_manage_reason", + "value": "需要管理WiFi连接以提供完整的网络控制功能" + }, + { + "name": "wifi_mac_reason", + "value": "需要获取WiFi MAC地址用于网络识别" + }, + { + "name": "location_reason", + "value": "需要位置权限以扫描附近的WiFi网络(系统要求)" + }, + { + "name": "location_approx_reason", + "value": "需要大致位置权限以扫描WiFi网络" + }, + { + "name": "module_desc", + "value": "React Native WiFi Manager - WiFi网络管理模块" + } + ] +} + +``` + +## 属性 + +> [!TIP] "Platform"列表示该属性在原三方库上支持的平台。 + +> [!TIP] "HarmonyOS Support"列为 yes 表示 HarmonyOS 平台支持该属性;no 则表示不支持;partially 表示部分支持。使用方法跨平台一致,效果对标 iOS 或 Android 的效果。droid 的效果。 + +**wifi-reborn**:适用于 React Native的 WiFi 管理第三方库,主要用于在应用中实现与设备 WiFi 功能相关的各种操作。 + +| Name | Description | Type | Required | Platform | HarmonyOS Support | +|-----------------|----------------------|----------|----------|-------------|-------------------| +| connectToProtectSSID | 连接到受保护的SSID | function | no | Android/IOS | yes | +| suggestWifiNetwork | 向移动设备系统推荐/提示指定可见的 WIFI 网络 | function | no | Android/IOS | yes | +| connectToProtectedWifiSSID | 连接到名为SSID的受保护的 WIFI | function | no | Android/IOS | yes | +| getCurrentWifiSSID | 返回当前WIFI网络的SSID | function | no | Android/IOS | yes | +| connectToSSID | 连接到SSID | function | no | IOS | yes | +| connectToSSIDPrefix | 连接到特定前缀的SSID | function | no | IOS | yes | +| disconnectFromSSID | 断开与SSID的连接 | function | no | IOS | yes | +| connectToProtectedSSIDOnce | 连接到受保护的SSID一次 | function | no | IOS | no | +| connectToProtectedSSIDPrefix | 连接到受保护的特定前缀的SSID | function | no | IOS | yes | +| connectToProtectedSSIDPrefixOnce | 连接到受保护的特定前缀的SSID一次 | function | no | IOS | no | +| loadWifiList | 返回附近WIFI网络列表 | function | no | Android | yes | +| reScanAndLoadWifiList | 重新扫描周边可见 WiFi 网络,并加载返回完整的 WiFi 列表数据 | function | no | Android | yes | +| isEnabled | 检查 WIFI 是否已开启 | function | no | Android | yes | +| setEnabled | 在设备上设置 WIFI 开启或关闭 | function | no | Android | yes | +| connectionStatus | 当前设备连接 WIFI 的状态,已连接返回true | function | no | Android | yes | +| disconnect | 断开当前连接的 WIFI | function | no | Android | yes | +| getBSSID | 返回当前连接 WIFI 的BSSID | function | no | Android | yes | +| getCurrentSignalStrength | 返回当前连接 WIFI 的RSSI(信号强度) | function | no | Android | yes | +| getFrequency | 返回当前连接的 WIFI 的信号频率 | function | no | Android | yes | +| getIP | 返回当前连接 WIFI 的IP地址 | function | no | Android | yes | +| isRemoveWifiNetwork | 移除设备中已保存配置的指定 WiFi 网络 | function | no | Android | yes | +| forceWifiUsage | 强制当前应用的网络请求走设备已连接的WIFI通道,忽略移动数据 | function | no | Android | yes | +| forceWifiUsageWithOptions | 强制当前应用的网络请求走设备已连接的WIFI通道,忽略移动数据(可传入配置对象) | function | no | Android | yes | + + +## 静态方法 + +## 遗留问题 + +## 其他 + +## 开源协议 + +本项目基于 [The MIT License (MIT)](https://github.com/JuanSeBestia/react-native-wifi-reborn/blob/master/LICENSE) ,请自由地享受和参与开源。 -- Gitee From f27dc24083d7ae4aca047c7ec079d11376fa7bc7 Mon Sep 17 00:00:00 2001 From: ZZZH Date: Sun, 4 Jan 2026 21:08:00 +0800 Subject: [PATCH 02/17] =?UTF-8?q?docs:=20[Issues:=20#IDHIT7]=E4=BF=AE?= =?UTF-8?q?=E6=94=B9react-native-wifi-reborn=E7=9A=84=E4=B8=AD=E8=8B=B1?= =?UTF-8?q?=E6=96=87=E6=8C=87=E5=AF=BC=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- en/react-native-wifi-reborn.md | 114 +++++++++++------------------- zh-cn/react-native-wifi-reborn.md | 114 +++++++++++------------------- 2 files changed, 86 insertions(+), 142 deletions(-) diff --git a/en/react-native-wifi-reborn.md b/en/react-native-wifi-reborn.md index ea4333f3..b04538e0 100644 --- a/en/react-native-wifi-reborn.md +++ b/en/react-native-wifi-reborn.md @@ -112,7 +112,7 @@ export const TurboLogDemoTest = () => { } }; - return ( + return ( @@ -156,12 +156,12 @@ export const TurboLogDemoTest = () => { - + - + { WifiManager.loadWifiList().then((list: any) => { updateResult("loadWifiList", "Loaded " + list.length + " networks"); @@ -174,9 +174,9 @@ export const TurboLogDemoTest = () => { - + { WifiManager.reScanAndLoadWifiList().then((list: any) => { updateResult("reScanAndLoadWifiList", "Loaded " + list.length + " networks"); @@ -214,9 +214,9 @@ export const TurboLogDemoTest = () => { - + { addLog(`Connecting to ${ssid}...`); WifiManager.connectToProtectedSSID(ssid, password, false, false) @@ -227,11 +227,11 @@ export const TurboLogDemoTest = () => { - + - + { addLog(`Connecting to ${ssid} with options...`); WifiManager.connectToProtectedWifiSSID({ @@ -268,12 +268,12 @@ export const TurboLogDemoTest = () => { - + { WifiManager.getCurrentWifiSSID() .then((ssid: any) => updateResult("getCurrentWifiSSID", "Current SSID: " + safeStringify(ssid))) @@ -285,9 +285,9 @@ export const TurboLogDemoTest = () => { - + { WifiManager.getBSSID() .then((bssid: any) => updateResult("getBSSID", "BSSID: " + safeStringify(bssid))) @@ -299,9 +299,9 @@ export const TurboLogDemoTest = () => { - + { WifiManager.getIP() .then((ip: any) => updateResult("getIP", "IP: " + safeStringify(ip))) @@ -313,9 +313,9 @@ export const TurboLogDemoTest = () => { - + { WifiManager.getFrequency() .then((freq: any) => updateResult("getFrequency", "Frequency: " + safeStringify(freq))) @@ -327,9 +327,9 @@ export const TurboLogDemoTest = () => { - + { WifiManager.getCurrentSignalStrength() .then((level: any) => updateResult("getCurrentSignalStrength", "Signal Strength: " + safeStringify(level))) @@ -341,9 +341,9 @@ export const TurboLogDemoTest = () => { - + { WifiManager.connectionStatus() .then((status: any) => updateResult("connectionStatus", "Connected: " + safeStringify(status))) @@ -355,9 +355,9 @@ export const TurboLogDemoTest = () => { - + { WifiManager.isEnabled() .then((enabled: any) => updateResult("isEnabled", "Wifi Enabled: " + safeStringify(enabled))) @@ -369,12 +369,12 @@ export const TurboLogDemoTest = () => { - + - + { try { WifiManager.setEnabled(true); @@ -407,7 +407,7 @@ export const TurboLogDemoTest = () => { - + { - + { WifiManager.isRemoveWifiNetwork(ssid) @@ -435,11 +435,11 @@ export const TurboLogDemoTest = () => { - + - + { WifiManager.forceWifiUsageWithOptions(true, { noInternet: true }) .then(() => updateResult("forceWifiUsageWithOptions", "Force Wifi Enabled")) @@ -465,12 +465,12 @@ export const TurboLogDemoTest = () => { - + - + { WifiManager.connectToSSID(ssid) .then(() => updateResult("connectToSSID", "Connected")) @@ -482,9 +482,9 @@ export const TurboLogDemoTest = () => { - + { WifiManager.connectToSSIDPrefix(ssid) .then(() => updateResult("connectToSSIDPrefix", "Connected")) @@ -496,9 +496,9 @@ export const TurboLogDemoTest = () => { - + { WifiManager.disconnectFromSSID(ssid) .then(() => updateResult("disconnectFromSSID", "Disconnected")) @@ -507,26 +507,12 @@ export const TurboLogDemoTest = () => { /> - - - - - { - WifiManager.connectToProtectedSSIDOnce(ssid, password, false, true) - .then(() => updateResult("connectToProtectedSSIDOnce", "Connected")) - .catch((err: any) => updateResult("connectToProtectedSSIDOnce", "Error: " + safeStringify(err))); - }} - /> - - - + { WifiManager.connectToProtectedSSIDPrefix(ssid, password, false) .then(() => updateResult("connectToProtectedSSIDPrefix", "Connected")) @@ -536,20 +522,6 @@ export const TurboLogDemoTest = () => { - - - - { - WifiManager.connectToProtectedSSIDPrefixOnce(ssid, password, false, true) - .then(() => updateResult("connectToProtectedSSIDPrefixOnce", "Connected")) - .catch((err: any) => updateResult("connectToProtectedSSIDPrefixOnce", "Error: " + safeStringify(err))); - }} - /> - - - diff --git a/zh-cn/react-native-wifi-reborn.md b/zh-cn/react-native-wifi-reborn.md index 34cdbff4..e4c48397 100644 --- a/zh-cn/react-native-wifi-reborn.md +++ b/zh-cn/react-native-wifi-reborn.md @@ -112,7 +112,7 @@ export const TurboLogDemoTest = () => { } }; - return ( + return ( @@ -156,12 +156,12 @@ export const TurboLogDemoTest = () => { - + - + { WifiManager.loadWifiList().then((list: any) => { updateResult("loadWifiList", "Loaded " + list.length + " networks"); @@ -174,9 +174,9 @@ export const TurboLogDemoTest = () => { - + { WifiManager.reScanAndLoadWifiList().then((list: any) => { updateResult("reScanAndLoadWifiList", "Loaded " + list.length + " networks"); @@ -214,9 +214,9 @@ export const TurboLogDemoTest = () => { - + { addLog(`Connecting to ${ssid}...`); WifiManager.connectToProtectedSSID(ssid, password, false, false) @@ -227,11 +227,11 @@ export const TurboLogDemoTest = () => { - + - + { addLog(`Connecting to ${ssid} with options...`); WifiManager.connectToProtectedWifiSSID({ @@ -268,12 +268,12 @@ export const TurboLogDemoTest = () => { - + { WifiManager.getCurrentWifiSSID() .then((ssid: any) => updateResult("getCurrentWifiSSID", "Current SSID: " + safeStringify(ssid))) @@ -285,9 +285,9 @@ export const TurboLogDemoTest = () => { - + { WifiManager.getBSSID() .then((bssid: any) => updateResult("getBSSID", "BSSID: " + safeStringify(bssid))) @@ -299,9 +299,9 @@ export const TurboLogDemoTest = () => { - + { WifiManager.getIP() .then((ip: any) => updateResult("getIP", "IP: " + safeStringify(ip))) @@ -313,9 +313,9 @@ export const TurboLogDemoTest = () => { - + { WifiManager.getFrequency() .then((freq: any) => updateResult("getFrequency", "Frequency: " + safeStringify(freq))) @@ -327,9 +327,9 @@ export const TurboLogDemoTest = () => { - + { WifiManager.getCurrentSignalStrength() .then((level: any) => updateResult("getCurrentSignalStrength", "Signal Strength: " + safeStringify(level))) @@ -341,9 +341,9 @@ export const TurboLogDemoTest = () => { - + { WifiManager.connectionStatus() .then((status: any) => updateResult("connectionStatus", "Connected: " + safeStringify(status))) @@ -355,9 +355,9 @@ export const TurboLogDemoTest = () => { - + { WifiManager.isEnabled() .then((enabled: any) => updateResult("isEnabled", "Wifi Enabled: " + safeStringify(enabled))) @@ -369,12 +369,12 @@ export const TurboLogDemoTest = () => { - + - + { try { WifiManager.setEnabled(true); @@ -407,7 +407,7 @@ export const TurboLogDemoTest = () => { - + { - + { WifiManager.isRemoveWifiNetwork(ssid) @@ -435,11 +435,11 @@ export const TurboLogDemoTest = () => { - + - + { WifiManager.forceWifiUsageWithOptions(true, { noInternet: true }) .then(() => updateResult("forceWifiUsageWithOptions", "Force Wifi Enabled")) @@ -465,12 +465,12 @@ export const TurboLogDemoTest = () => { - + - + { WifiManager.connectToSSID(ssid) .then(() => updateResult("connectToSSID", "Connected")) @@ -482,9 +482,9 @@ export const TurboLogDemoTest = () => { - + { WifiManager.connectToSSIDPrefix(ssid) .then(() => updateResult("connectToSSIDPrefix", "Connected")) @@ -496,9 +496,9 @@ export const TurboLogDemoTest = () => { - + { WifiManager.disconnectFromSSID(ssid) .then(() => updateResult("disconnectFromSSID", "Disconnected")) @@ -507,26 +507,12 @@ export const TurboLogDemoTest = () => { /> - - - - - { - WifiManager.connectToProtectedSSIDOnce(ssid, password, false, true) - .then(() => updateResult("connectToProtectedSSIDOnce", "Connected")) - .catch((err: any) => updateResult("connectToProtectedSSIDOnce", "Error: " + safeStringify(err))); - }} - /> - - - + { WifiManager.connectToProtectedSSIDPrefix(ssid, password, false) .then(() => updateResult("connectToProtectedSSIDPrefix", "Connected")) @@ -536,20 +522,6 @@ export const TurboLogDemoTest = () => { - - - - { - WifiManager.connectToProtectedSSIDPrefixOnce(ssid, password, false, true) - .then(() => updateResult("connectToProtectedSSIDPrefixOnce", "Connected")) - .catch((err: any) => updateResult("connectToProtectedSSIDPrefixOnce", "Error: " + safeStringify(err))); - }} - /> - - - -- Gitee From 7c05a5715b5858caef05080be4d6c7debd0c705a Mon Sep 17 00:00:00 2001 From: ZZZH Date: Mon, 5 Jan 2026 15:50:34 +0800 Subject: [PATCH 03/17] =?UTF-8?q?docs:=20[Issues:=20#IDHIT7]=E4=BF=AE?= =?UTF-8?q?=E6=94=B9react-native-wifi-reborn=E7=9A=84=E4=B8=AD=E8=8B=B1?= =?UTF-8?q?=E6=96=87=E6=8C=87=E5=AF=BC=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- en/react-native-wifi-reborn.md | 2 ++ zh-cn/react-native-wifi-reborn.md | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/en/react-native-wifi-reborn.md b/en/react-native-wifi-reborn.md index b04538e0..a6970402 100644 --- a/en/react-native-wifi-reborn.md +++ b/en/react-native-wifi-reborn.md @@ -933,6 +933,8 @@ Open 'entry/src/main/resources/base/element/string. json' and add: ## other +•The connectToProtectdSSIDOnce and connectToProtectdSSIDPriorityOnce methods cannot be implemented. These two methods are specifically designed for the iOS platform and use the NEHotspotConfiguring Manager to pass the joinOnce parameter in the iOS system to achieve one-time connection functionality. However, HarmonyOS does not support this feature. + ## open source license diff --git a/zh-cn/react-native-wifi-reborn.md b/zh-cn/react-native-wifi-reborn.md index e4c48397..609545cf 100644 --- a/zh-cn/react-native-wifi-reborn.md +++ b/zh-cn/react-native-wifi-reborn.md @@ -934,6 +934,10 @@ ohpm install ## 其他 +•connectToProtectedSSIDOnce和connectToProtectedSSIDPrefixOnce方法无法实现,这两个方法是专门为ios平台设计的,在ios系统中使用了NEHotspotConfigurationManager传递joinOnce参数来实现一次连接功能,鸿蒙侧不支持此功能。 + + + ## 开源协议 本项目基于 [The MIT License (MIT)](https://github.com/JuanSeBestia/react-native-wifi-reborn/blob/master/LICENSE) ,请自由地享受和参与开源。 -- Gitee From 39bd65c27770e871e1f6ddc2001b53426c505f42 Mon Sep 17 00:00:00 2001 From: ZZZH Date: Tue, 6 Jan 2026 10:32:42 +0800 Subject: [PATCH 04/17] =?UTF-8?q?docs:=20[Issues:=20#IDHIT7]=E4=BF=AE?= =?UTF-8?q?=E6=94=B9react-native-wifi-reborn=E7=9A=84=E4=B8=AD=E8=8B=B1?= =?UTF-8?q?=E6=96=87=E6=8C=87=E5=AF=BC=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- en/react-native-wifi-reborn.md | 162 +++--------------------------- zh-cn/react-native-wifi-reborn.md | 162 +++--------------------------- 2 files changed, 30 insertions(+), 294 deletions(-) diff --git a/en/react-native-wifi-reborn.md b/en/react-native-wifi-reborn.md index a6970402..244dd0b9 100644 --- a/en/react-native-wifi-reborn.md +++ b/en/react-native-wifi-reborn.md @@ -191,8 +191,8 @@ export const TurboLogDemoTest = () => { Available Networks {wifiList.map((item, index) => ( - { setSsid(item.SSID); @@ -219,34 +219,20 @@ export const TurboLogDemoTest = () => { title="connectToProtectedSSID" onPress={() => { addLog(`Connecting to ${ssid}...`); - WifiManager.connectToProtectedSSID(ssid, password, false, false) - .then(() => updateResult("connectToProtectedSSID", "Connected to " + ssid)) - .catch((err: any) => updateResult("connectToProtectedSSID", "Error: " + safeStringify(err))); + if (password.length < 8) { + Alert.alert('密码需大于8位字符') + return + } else { + WifiManager.connectToProtectedSSID(ssid, password, false, false) + .then(() => updateResult("connectToProtectedSSID", "Connected to " + ssid)) + .catch((err: any) => updateResult("connectToProtectedSSID", "Error: " + safeStringify(err))); + } + }} /> - - - - { - addLog(`Connecting to ${ssid} with options...`); - WifiManager.connectToProtectedWifiSSID({ - ssid: ssid, - password: password, - isWEP: false, - isHidden: false - }) - .then(() => updateResult("connectToProtectedWifiSSID", "Connected to " + ssid)) - .catch((err: any) => updateResult("connectToProtectedWifiSSID", "Error: " + safeStringify(err))); - }} - /> - - - @@ -311,34 +297,6 @@ export const TurboLogDemoTest = () => { - - - - { - WifiManager.getFrequency() - .then((freq: any) => updateResult("getFrequency", "Frequency: " + safeStringify(freq))) - .catch((err: any) => updateResult("getFrequency", "Error: " + safeStringify(err))); - }} - /> - - - - - - - { - WifiManager.getCurrentSignalStrength() - .then((level: any) => updateResult("getCurrentSignalStrength", "Signal Strength: " + safeStringify(level))) - .catch((err: any) => updateResult("getCurrentSignalStrength", "Error: " + safeStringify(err))); - }} - /> - - - @@ -353,58 +311,10 @@ export const TurboLogDemoTest = () => { - - - - { - WifiManager.isEnabled() - .then((enabled: any) => updateResult("isEnabled", "Wifi Enabled: " + safeStringify(enabled))) - .catch((err: any) => updateResult("isEnabled", "Error: " + safeStringify(err))); - }} - /> - - - + - - - - { - try { - WifiManager.setEnabled(true); - updateResult("setEnabledTrue", "Request to enable Wifi sent"); - } catch (err) { - updateResult("setEnabledTrue", "Error: " + safeStringify(err)); - } - }} - /> - - - - - - - { - try { - WifiManager.setEnabled(false); - updateResult("setEnabledFalse", "Request to disable Wifi sent"); - } catch (err) { - updateResult("setEnabledFalse", "Error: " + safeStringify(err)); - } - }} - /> - - - @@ -435,25 +345,11 @@ export const TurboLogDemoTest = () => { - - - - { - WifiManager.forceWifiUsageWithOptions(true, { noInternet: true }) - .then(() => updateResult("forceWifiUsageWithOptions", "Force Wifi Enabled")) - .catch((err: any) => updateResult("forceWifiUsageWithOptions", "Error: " + safeStringify(err))); - }} - /> - - - - + - + { WifiManager.forceWifiUsage(true) .then(() => updateResult("forceWifiUsage", "Force Wifi Enabled")) @@ -480,20 +376,6 @@ export const TurboLogDemoTest = () => { - - - - { - WifiManager.connectToSSIDPrefix(ssid) - .then(() => updateResult("connectToSSIDPrefix", "Connected")) - .catch((err: any) => updateResult("connectToSSIDPrefix", "Error: " + safeStringify(err))); - }} - /> - - - @@ -508,20 +390,6 @@ export const TurboLogDemoTest = () => { - - - - { - WifiManager.connectToProtectedSSIDPrefix(ssid, password, false) - .then(() => updateResult("connectToProtectedSSIDPrefix", "Connected")) - .catch((err: any) => updateResult("connectToProtectedSSIDPrefix", "Error: " + safeStringify(err))); - }} - /> - - - diff --git a/zh-cn/react-native-wifi-reborn.md b/zh-cn/react-native-wifi-reborn.md index 609545cf..6bf3db35 100644 --- a/zh-cn/react-native-wifi-reborn.md +++ b/zh-cn/react-native-wifi-reborn.md @@ -191,8 +191,8 @@ export const TurboLogDemoTest = () => { Available Networks {wifiList.map((item, index) => ( - { setSsid(item.SSID); @@ -219,34 +219,20 @@ export const TurboLogDemoTest = () => { title="connectToProtectedSSID" onPress={() => { addLog(`Connecting to ${ssid}...`); - WifiManager.connectToProtectedSSID(ssid, password, false, false) - .then(() => updateResult("connectToProtectedSSID", "Connected to " + ssid)) - .catch((err: any) => updateResult("connectToProtectedSSID", "Error: " + safeStringify(err))); + if (password.length < 8) { + Alert.alert('密码需大于8位字符') + return + } else { + WifiManager.connectToProtectedSSID(ssid, password, false, false) + .then(() => updateResult("connectToProtectedSSID", "Connected to " + ssid)) + .catch((err: any) => updateResult("connectToProtectedSSID", "Error: " + safeStringify(err))); + } + }} /> - - - - { - addLog(`Connecting to ${ssid} with options...`); - WifiManager.connectToProtectedWifiSSID({ - ssid: ssid, - password: password, - isWEP: false, - isHidden: false - }) - .then(() => updateResult("connectToProtectedWifiSSID", "Connected to " + ssid)) - .catch((err: any) => updateResult("connectToProtectedWifiSSID", "Error: " + safeStringify(err))); - }} - /> - - - @@ -311,34 +297,6 @@ export const TurboLogDemoTest = () => { - - - - { - WifiManager.getFrequency() - .then((freq: any) => updateResult("getFrequency", "Frequency: " + safeStringify(freq))) - .catch((err: any) => updateResult("getFrequency", "Error: " + safeStringify(err))); - }} - /> - - - - - - - { - WifiManager.getCurrentSignalStrength() - .then((level: any) => updateResult("getCurrentSignalStrength", "Signal Strength: " + safeStringify(level))) - .catch((err: any) => updateResult("getCurrentSignalStrength", "Error: " + safeStringify(err))); - }} - /> - - - @@ -353,58 +311,10 @@ export const TurboLogDemoTest = () => { - - - - { - WifiManager.isEnabled() - .then((enabled: any) => updateResult("isEnabled", "Wifi Enabled: " + safeStringify(enabled))) - .catch((err: any) => updateResult("isEnabled", "Error: " + safeStringify(err))); - }} - /> - - - + - - - - { - try { - WifiManager.setEnabled(true); - updateResult("setEnabledTrue", "Request to enable Wifi sent"); - } catch (err) { - updateResult("setEnabledTrue", "Error: " + safeStringify(err)); - } - }} - /> - - - - - - - { - try { - WifiManager.setEnabled(false); - updateResult("setEnabledFalse", "Request to disable Wifi sent"); - } catch (err) { - updateResult("setEnabledFalse", "Error: " + safeStringify(err)); - } - }} - /> - - - @@ -435,25 +345,11 @@ export const TurboLogDemoTest = () => { - - - - { - WifiManager.forceWifiUsageWithOptions(true, { noInternet: true }) - .then(() => updateResult("forceWifiUsageWithOptions", "Force Wifi Enabled")) - .catch((err: any) => updateResult("forceWifiUsageWithOptions", "Error: " + safeStringify(err))); - }} - /> - - - - + - + { WifiManager.forceWifiUsage(true) .then(() => updateResult("forceWifiUsage", "Force Wifi Enabled")) @@ -480,20 +376,6 @@ export const TurboLogDemoTest = () => { - - - - { - WifiManager.connectToSSIDPrefix(ssid) - .then(() => updateResult("connectToSSIDPrefix", "Connected")) - .catch((err: any) => updateResult("connectToSSIDPrefix", "Error: " + safeStringify(err))); - }} - /> - - - @@ -508,20 +390,6 @@ export const TurboLogDemoTest = () => { - - - - { - WifiManager.connectToProtectedSSIDPrefix(ssid, password, false) - .then(() => updateResult("connectToProtectedSSIDPrefix", "Connected")) - .catch((err: any) => updateResult("connectToProtectedSSIDPrefix", "Error: " + safeStringify(err))); - }} - /> - - - -- Gitee From d29dbdb2e71c21720e937634c089d3f6d0272f84 Mon Sep 17 00:00:00 2001 From: ZZZH Date: Tue, 6 Jan 2026 11:04:52 +0800 Subject: [PATCH 05/17] =?UTF-8?q?docs:=20[Issues:=20#IDHIT7]=E4=BF=AE?= =?UTF-8?q?=E6=94=B9react-native-wifi-reborn=E7=9A=84=E4=B8=AD=E8=8B=B1?= =?UTF-8?q?=E6=96=87=E6=8C=87=E5=AF=BC=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- en/react-native-wifi-reborn.md | 658 ++++++++++++++++++++++++++++++ zh-cn/react-native-wifi-reborn.md | 658 ++++++++++++++++++++++++++++++ 2 files changed, 1316 insertions(+) create mode 100644 en/react-native-wifi-reborn.md create mode 100644 zh-cn/react-native-wifi-reborn.md diff --git a/en/react-native-wifi-reborn.md b/en/react-native-wifi-reborn.md new file mode 100644 index 00000000..651d4a3b --- /dev/null +++ b/en/react-native-wifi-reborn.md @@ -0,0 +1,658 @@ +> Template Version: v0.2.2 + +

+

react-native-wifi-reborn

+

+ +Please check the release information of the corresponding version at the third-party library's Releases page: + +| Third-Party Library Version | Release Information | Supported RN Version | +| --------------------------- | --------------------------------------------------------------- | -------------------- | +| 0.6.1 | [@react-native-ohos/react-native-wifi-reborn Releases](https://github.com/react-native-oh-library/react-native-wifi-reborn/releases) | 0.72 | +| 0.7.0 | [@react-native-ohos/react-native-wifi-reborn Releases](https://github.com/react-native-oh-library/react-native-wifi-reborn/releases) | 0.77 | + +> [!TIP] [GitHub Address](https://github.com/react-native-oh-library/react-native-wifi-reborn) + +## Installation and Usage + +Navigate to the project directory and enter the following command: + + + + +#### npm + +```bash +npm install @react-native-ohos/react-native-wifi-reborn +``` + +#### yarn + +```bash +yarn add @react-native-ohos/react-native-wifi-reborn +``` + + + +The following code demonstrates the basic usage scenarios of this library: + +> [!WARNING] The library name used in the import remains unchanged. +### wifi-reborn example +``` js +import React, { useState } from 'react'; +import { ScrollView, StyleSheet, Text, TouchableOpacity, View, TextInput, Alert } from 'react-native'; +import { Tester, TestSuite, TestCase } from '@rnoh/testerino'; +import WifiManager from 'react-native-wifi-reborn'; +import RTNPermissions, { Permission } from "react-native-permissions"; + +const permissionNormal: Permission[] = [ + 'ohos.permission.GET_WIFI_INFO', + 'ohos.permission.SET_WIFI_INFO', + 'ohos.permission.LOCATION', + 'ohos.permission.MANAGE_WIFI_CONNECTION', + 'ohos.permission.GET_WIFI_LOCAL_MAC', + 'ohos.permission.APPROXIMATELY_LOCATION', +]; + +const COLORS = { + primary: '#007AFF', + secondary: '#5856D6', + success: '#4CD964', + background: '#F2F2F7', + card: '#FFFFFF', + text: '#000000', + subText: '#8E8E93', + border: '#C7C7CC', + error: '#FF3B30', +}; + +const CustomButton = ({ title, onPress, color = COLORS.primary }: { title: string, onPress: () => void, color?: string }) => ( + + {title} + +); + +const ResultArea = ({ text }: { text: string }) => { + if (!text) return null; + return ( + + Result: + {text} + + ); +}; + +const Description = ({ text }: { text: string }) => ( + {text} +); + +export const TurboLogDemoTest = () => { + const [wifiList, setWifiList] = useState([]); + const [ssid, setSsid] = useState(''); + const [password, setPassword] = useState(''); + const [log, setLog] = useState(''); + const [results, setResults] = useState<{ [key: string]: string }>({}); + + const addLog = (msg: string) => { + console.info(msg); + setLog(prev => msg + '\n' + prev); + }; + + const updateResult = (key: string, value: string) => { + setResults(prev => ({ ...prev, [key]: value })); + addLog(`${key}: ${value}`); + }; + + const safeStringify = (val: any) => { + if (typeof val === 'string') return val; + try { + return JSON.stringify(val, null, 2); + } catch (e) { + return String(val); + } + }; + + return ( + + + + Wifi Manager Demo + + + + + + + + + + + { + try { + let requestMultiple = await RTNPermissions.requestMultiple(permissionNormal); + updateResult("Permissions", safeStringify(requestMultiple)); + } catch (e) { + updateResult("Permissions", "Error: " + safeStringify(e)); + } + }} + /> + + + + + + + + + + { + WifiManager.loadWifiList().then((list: any) => { + updateResult("loadWifiList", "Loaded " + list.length + " networks"); + setWifiList(list); + }).catch((err: any) => updateResult("loadWifiList", "Error: " + safeStringify(err))); + }} + /> + + + + {wifiList.length > 0 && ( + + Available Networks + {wifiList.map((item, index) => ( + { + setSsid(item.SSID); + addLog("Selected SSID: " + item.SSID); + }} + > + + {item.SSID || ''} + {item.level} dBm + + {item.BSSID} + {item.capabilities} + + ))} + + )} + + + + + + + { + addLog(`Connecting to ${ssid}...`); + if (password.length < 8) { + Alert.alert('密码需大于8位字符') + return + } else { + WifiManager.connectToProtectedSSID(ssid, password, false, false) + .then(() => updateResult("connectToProtectedSSID", "Connected to " + ssid)) + .catch((err: any) => updateResult("connectToProtectedSSID", "Error: " + safeStringify(err))); + } + + }} + /> + + + + + + + + + + { + WifiManager.disconnect() + .then((res: any) => updateResult("disconnect", "Disconnect: " + safeStringify(res))) + .catch((err: any) => updateResult("disconnect", "Error: " + safeStringify(err))); + }} + /> + + + + + + + + ); +}; + +const styles = StyleSheet.create({ + headerContainer: { + backgroundColor: COLORS.background, + padding: 10, + borderBottomWidth: 1, + borderBottomColor: COLORS.border, + elevation: 2, + zIndex: 100, + }, + headerTitle: { + fontSize: 20, + fontWeight: 'bold', + color: COLORS.text, + marginBottom: 10, + textAlign: 'center', + }, + inputCard: { + backgroundColor: COLORS.card, + borderRadius: 10, + padding: 10, + shadowColor: '#000', + shadowOffset: { width: 0, height: 2 }, + shadowOpacity: 0.1, + shadowRadius: 4, + elevation: 3, + }, + input: { + height: 44, + borderColor: COLORS.border, + borderWidth: 1, + borderRadius: 8, + marginBottom: 10, + paddingHorizontal: 12, + backgroundColor: '#FAFAFA', + fontSize: 16, + color: COLORS.text, + }, + testCaseContent: { + padding: 10, + }, + button: { + paddingVertical: 12, + paddingHorizontal: 20, + borderRadius: 8, + alignItems: 'center', + justifyContent: 'center', + elevation: 2, + shadowColor: '#000', + shadowOffset: { width: 0, height: 1 }, + shadowOpacity: 0.2, + shadowRadius: 2, + }, + buttonText: { + color: 'white', + fontSize: 16, + fontWeight: '600', + }, + resultContainer: { + marginTop: 10, + padding: 10, + backgroundColor: '#F8F9FA', + borderRadius: 6, + borderLeftWidth: 4, + borderLeftColor: COLORS.secondary, + }, + resultLabel: { + fontSize: 12, + color: COLORS.subText, + marginBottom: 4, + fontWeight: '600', + }, + resultText: { + fontSize: 14, + color: COLORS.text, + fontFamily: 'monospace', + }, + descriptionText: { + fontSize: 13, + color: '#666', + marginBottom: 10, + lineHeight: 18, + fontStyle: 'italic', + }, + wifiListContainer: { + padding: 10, + backgroundColor: COLORS.background, + }, + sectionTitle: { + fontSize: 18, + fontWeight: 'bold', + color: COLORS.text, + marginBottom: 10, + marginLeft: 5, + }, + wifiItem: { + padding: 15, + backgroundColor: COLORS.card, + borderRadius: 10, + marginBottom: 8, + shadowColor: '#000', + shadowOffset: { width: 0, height: 1 }, + shadowOpacity: 0.1, + shadowRadius: 2, + elevation: 2, + }, + wifiItemHeader: { + flexDirection: 'row', + justifyContent: 'space-between', + alignItems: 'center', + marginBottom: 4, + }, + wifiSSID: { + fontSize: 16, + fontWeight: 'bold', + color: COLORS.text, + }, + wifiLevel: { + fontSize: 14, + color: COLORS.success, + fontWeight: '600', + }, + wifiBSSID: { + fontSize: 12, + color: COLORS.subText, + marginBottom: 2, + }, + wifiDetails: { + fontSize: 11, + color: COLORS.subText, + fontStyle: 'italic', + }, +}); + + +``` +## Link + +This step provides guidance for manually configuring native dependencies. + +First, use DevEco Studio to open the HarmonyOS project `harmony` in your project. + +### 1. Add the `overrides` field to the `oh-package.json` file in the root directory of the project. + +```json +{ + ... + "overrides": { + "@rnoh/react-native-openharmony" : "./react_native_openharmony" + } + ... +} +``` + +### 2. Introduce Native Code + +Currently, there are two methods: + +1. Import via har package (this method will be deprecated after the IDE improves related features; currently, it is the preferred method); +2. Directly link the source code. + +**Method 1: Import via har package (Recommended)** + +> [!TIP] The har package is located in the `harmony` folder under the third-party library installation path. + +Open `entry/oh-package.json5` and add the following dependencies. + +```json +"dependencies": { + "@rnoh/react-native-openharmony": "file:../react_native_openharmony", + "@react-native-ohos/react-native-wifi-reborn": "file:../../node_modules/@react-native-ohos/react-native-wifi-reborn/harmony/wifi_reborn.har" + } +``` + +Click the `sync` button in the top right corner + +Or execute in the terminal: + +```bash +cd entry +ohpm install +``` + +Method 2: Directly link the source code + +> [!TIP] If you need to use direct source code linking, refer to [Direct Source Code Linking Instructions](/zh-cn/link-source-code.md) + + +### 4. Configure CMakeLists and introduce turbo_log + +Open `entry/src/main/cpp/CMakeLists.txt` and add: + +```diff +include(FetchContent) +# BOOST +set(BOOST_ENABLE_CMAKE On) +FetchContent_Declare( + Boost + URL /7277/boost-1.82.0.tar.xz + OVERRIDE_FIND_PACKAGE) +project(rnapp) +cmake_minimum_required(VERSION 3.4.1) +set(CMAKE_SKIP_BUILD_RPATH TRUE) +set(RNOH_APP_DIR "${CMAKE_CURRENT_SOURCE_DIR}") +set(NODE_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../node_modules") ++ set(OH_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/../../../oh_modules") +set(RNOH_CPP_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../../oh_modules/@rnoh/react-native-openharmony/src/main/cpp") +set(RNOH_GENERATED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/generated") +set(LOG_VERBOSITY_LEVEL 1) +set(CMAKE_ASM_FLAGS "-Wno-error=unused-command-line-argument -Qunused-arguments") +set(CMAKE_CXX_FLAGS "-fstack-protector-strong -Wl,-z,relro,-z,now,-z,noexecstack -s -fPIE -pie") +set(WITH_HITRACE_SYSTRACE 1) # for other CMakeLists.txt files to use +add_compile_definitions(WITH_HITRACE_SYSTRACE) + + +add_subdirectory("${RNOH_CPP_DIR}" ./rn) + +# RNOH_BEGIN: manual_package_linking_1 +add_subdirectory("${OH_MODULES}/@react-native-ohos/react-native-gesture-handler/src/main/cpp" ./gesture-handler) ++ add_subdirectory("${OH_MODULES}/@react-native-ohos/react-native-wifi-reborn/src/main/cpp" ./wifi_reborn) +# RNOH_END: manual_package_linking_1 + +file(GLOB GENERATED_CPP_FILES "./generated/*.cpp") # this line is needed by codegen v1 +add_library(rnoh_app SHARED + ${GENERATED_CPP_FILES} + "./PackageProvider.cpp" + "${RNOH_CPP_DIR}/RNOHAppNapiBridge.cpp" +) +target_link_libraries(rnoh_app PUBLIC rnoh) + +# RNOH_BEGIN: manual_package_linking_2 +target_link_libraries(rnoh_app PUBLIC rnoh_gesture_handler) ++ target_link_libraries(rnoh_app PUBLIC rnoh_wifi_reborn) +# RNOH_END: manual_package_linking_2 + +``` + +### 4.Import the TurboLogPackage on the ArkTS side + +打开 `entry/src/main/cpp/PackageProvider.cpp`,添加: + +```diff +#include "RNOH/PackageProvider.h" +#include "generated/RNOHGeneratedPackage.h" +#include "SamplePackage.h" ++ #include "WifiRebornPackage.h" + +using namespace rnoh; + +std::vector> PackageProvider::getPackages(Package::Context ctx) { + return { + std::make_shared(ctx), + std::make_shared(ctx), ++ std::make_shared(ctx), + }; +} +``` + +### 5. Run + +Click the `sync` button in the top right corner. + +Or execute the following in the terminal: + +```bash +cd entry +ohpm install +``` + +Then compile and run. + +## Constraints and Limitations + +### Compatibility + +The content of this document has been verified with the following versions: +1. RNOH: 0.72.90; SDK: HarmonyOS NEXT Developer DB3; IDE: DevEco Studio: 5.0.5.220; ROM: NEXT.0.0.105; +2. RNOH: 0.77.18; SDK: HarmonyOS 6.0.0 Release; IDE: DevEco Studio 6.0.0.858; ROM: 6.0.0.112; + +### Permission requirements +Among the following permissions, there is a 'system_masic' permission, while the default application permission is' normal ', which can only be used at the' normal 'level. Therefore, when installing the HAP package, an error may occur * * 9568289 * *, please refer to the [document]( https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/bm-tool-V5#ZH -CN_TOPIC_0000001884757326__%E5%AE%89%E8%A3%85hap%E6%97%B6%E6%8F%90%E7%A4%BAcode9568289-error-install-failed-due-to-grant-request-permissions-failed) Change the application level to 'system_masic'` + +#### Add permissions to module.json5 in the entry directory + +Open 'entry/src/main/module. json5' and add: + +```diff +... +"requestPermissions": [ + { + "name": "ohos.permission.GET_WIFI_INFO", + "reason": "$string:wifi_info_reason", + "usedScene": { + "abilities": [], + "when": "inuse" + } + }, + { + "name": "ohos.permission.SET_WIFI_INFO", + "reason": "$string:wifi_set_reason", + "usedScene": { + "abilities": [], + "when": "inuse" + } + }, + { + "name": "ohos.permission.LOCATION", + "reason": "$string:location_reason", + "usedScene": { + "abilities": [], + "when": "inuse" + } + }, + { + "name": "ohos.permission.APPROXIMATELY_LOCATION", + "reason": "$string:location_approx_reason", + "usedScene": { + "abilities": [], + "when": "inuse" + } + } + ], +``` + +#### Add the reason for applying for the above permissions in the entry directory + +Open 'entry/src/main/resources/base/element/string. json' and add: + +```diff +... +{ + "string": [ + { + "name": "wifi_info_reason", + "value": "需要获取WiFi信息以显示当前连接的网络状态" + }, + { + "name": "wifi_set_reason", + "value": "需要配置WiFi网络以连接到指定的无线网络" + }, + { + "name": "wifi_manage_reason", + "value": "需要管理WiFi连接以提供完整的网络控制功能" + }, + { + "name": "wifi_mac_reason", + "value": "需要获取WiFi MAC地址用于网络识别" + }, + { + "name": "location_reason", + "value": "需要位置权限以扫描附近的WiFi网络(系统要求)" + }, + { + "name": "location_approx_reason", + "value": "需要大致位置权限以扫描WiFi网络" + }, + { + "name": "module_desc", + "value": "React Native WiFi Manager - WiFi网络管理模块" + } + ] +} + +``` + +## Attributes + +> [!TIP] The "Platform" column indicates the platforms supported by the original third-party library. + +> [!TIP] The "HarmonyOS Support" column shows "yes" if the attribute is supported on the HarmonyOS platform, "no" if not supported, and "partially" if partially supported. The usage method is consistent across platforms, and the effect aligns with that of iOS or Android. + +**wifi-reborn**:A third-party library for WiFi management in React Native, mainly used to implement various operations related to device WiFi functionality in applications. + +| Name | Description | Type | Required | Platform | HarmonyOS Support | +|-----------------|----------------------|----------|----------|-------------|-------------------| +| connectToProtectSSID | Connect to a protected SSID | function | no | Android/IOS | yes | +| suggestWifiNetwork | Recommend/prompt the specified visible WIFI network to the mobile device system | function | no | Android/IOS | yes | +| connectToProtectedWifiSSID | Connect to the protected WIFI named SSID | function | no | Android/IOS | yes | +| getCurrentWifiSSID | Return the SSID of the current WiFi network | function | no | Android/IOS | yes | +| connectToSSID | Connect to SSID | function | no | IOS | yes | +| connectToSSIDPrefix | Connect to SSID with a specific prefix | function | no | IOS | yes | +| disconnectFromSSID | Disconnect from SSID | function | no | IOS | yes | +| connectToProtectedSSIDOnce | Connect to the protected SSID once | function | no | IOS | no | +| connectToProtectedSSIDPrefix | Connect to a protected SSID with a specific prefix | function | no | IOS | yes | +| connectToProtectedSSIDPrefixOnce | Connect to a protected SSID with a specific prefix once | function | no | IOS | no | +| loadWifiList | Return to the list of nearby WIFI networks | function | no | Android | yes | +| reScanAndLoadWifiList | Rescan visible WiFi networks in the surrounding area and load and return the complete WiFi list data | function | no | Android | yes | +| isEnabled | Check if WIFI is turned on | function | no | Android | yes | +| setEnabled | Set WIFI on or off on the device | function | no | Android | yes | +| connectionStatus | The current device is connected to WIFI and has been connected, returning true | function | no | Android | yes | +| disconnect | Disconnect the current WIFI connection | function | no | Android | yes | +| getBSSID | Return the BSSID of the current WIFI connection | function | no | Android | yes | +| getCurrentSignalStrength | Return the RSSI (signal strength) of the current WIFI connection | function | no | Android | yes | +| getFrequency | Return the signal frequency of the currently connected WIFI | function | no | Android | yes | +| getIP | Return the IP address of the current WIFI connection | function | no | Android | yes | +| isRemoveWifiNetwork | Remove the specified WiFi network with saved configuration from the device | function | no | Android | yes | +| forceWifiUsage | Force the current application's network requests to go through the WIFI channel that the device is already connected to, ignoring mobile data | function | no | Android | yes | +| forceWifiUsageWithOptions | Force the current application's network requests to go through the WIFI channel that the device is already connected to, ignoring mobile data (which can be passed into the configuration object) | function | no | Android | yes | + + +## Static method + +## outstanding issues + +## other + +•The connectToProtectdSSIDOnce and connectToProtectdSSIDPriorityOnce methods cannot be implemented. These two methods are specifically designed for the iOS platform and use the NEHotspotConfiguring Manager to pass the joinOnce parameter in the iOS system to achieve one-time connection functionality. However, HarmonyOS does not support this feature. + + +## open source license + + +This project is based on [The MIT License (MIT)]( https://github.com/JuanSeBestia/react-native-wifi-reborn/blob/master/LICENSE )Please enjoy and participate freely in open source. + diff --git a/zh-cn/react-native-wifi-reborn.md b/zh-cn/react-native-wifi-reborn.md new file mode 100644 index 00000000..2bd1c4ac --- /dev/null +++ b/zh-cn/react-native-wifi-reborn.md @@ -0,0 +1,658 @@ +> 模板版本:v0.2.2 + +

+

react-native-wifi-reborn

+

+ +请到三方库的 Releases 发布地址查看配套的版本信息: + +| 三方库版本 | 发布信息 | 支持RN版本 | +| ---------- | ------------------------------------------------------------ | ---------- | +| 0.6.1 | [@react-native-ohos/react-native-wifi-reborn Releases](https://github.com/react-native-oh-library/react-native-wifi-reborn/releases) | 0.72 | +| 0.7.0 | [@react-native-ohos/react-native-wifi-reborn Releases](https://github.com/react-native-oh-library/react-native-wifi-reborn/releases) | 0.77 | + +> [!TIP] [Github 地址](https://github.com/react-native-oh-library/react-native-wifi-reborn) + +## 安装与使用 + +进入到工程目录并输入以下命令: + + + + +#### npm + +```bash +npm install @react-native-ohos/react-native-wifi-reborn +``` + +#### yarn + +```bash +yarn add @react-native-ohos/react-native-wifi-reborn +``` + + + +下面的代码展示了这个库的基本使用场景: + +> [!WARNING] 使用时 import 的库名不变。 +### wifi-reborn example +``` js +import React, { useState } from 'react'; +import { ScrollView, StyleSheet, Text, TouchableOpacity, View, TextInput, Alert } from 'react-native'; +import { Tester, TestSuite, TestCase } from '@rnoh/testerino'; +import WifiManager from 'react-native-wifi-reborn'; +import RTNPermissions, { Permission } from "react-native-permissions"; + +const permissionNormal: Permission[] = [ + 'ohos.permission.GET_WIFI_INFO', + 'ohos.permission.SET_WIFI_INFO', + 'ohos.permission.LOCATION', + 'ohos.permission.MANAGE_WIFI_CONNECTION', + 'ohos.permission.GET_WIFI_LOCAL_MAC', + 'ohos.permission.APPROXIMATELY_LOCATION', +]; + +const COLORS = { + primary: '#007AFF', + secondary: '#5856D6', + success: '#4CD964', + background: '#F2F2F7', + card: '#FFFFFF', + text: '#000000', + subText: '#8E8E93', + border: '#C7C7CC', + error: '#FF3B30', +}; + +const CustomButton = ({ title, onPress, color = COLORS.primary }: { title: string, onPress: () => void, color?: string }) => ( + + {title} + +); + +const ResultArea = ({ text }: { text: string }) => { + if (!text) return null; + return ( + + Result: + {text} + + ); +}; + +const Description = ({ text }: { text: string }) => ( + {text} +); + +export const TurboLogDemoTest = () => { + const [wifiList, setWifiList] = useState([]); + const [ssid, setSsid] = useState(''); + const [password, setPassword] = useState(''); + const [log, setLog] = useState(''); + const [results, setResults] = useState<{ [key: string]: string }>({}); + + const addLog = (msg: string) => { + console.info(msg); + setLog(prev => msg + '\n' + prev); + }; + + const updateResult = (key: string, value: string) => { + setResults(prev => ({ ...prev, [key]: value })); + addLog(`${key}: ${value}`); + }; + + const safeStringify = (val: any) => { + if (typeof val === 'string') return val; + try { + return JSON.stringify(val, null, 2); + } catch (e) { + return String(val); + } + }; + + return ( + + + + Wifi Manager Demo + + + + + + + + + + + { + try { + let requestMultiple = await RTNPermissions.requestMultiple(permissionNormal); + updateResult("Permissions", safeStringify(requestMultiple)); + } catch (e) { + updateResult("Permissions", "Error: " + safeStringify(e)); + } + }} + /> + + + + + + + + + + { + WifiManager.loadWifiList().then((list: any) => { + updateResult("loadWifiList", "Loaded " + list.length + " networks"); + setWifiList(list); + }).catch((err: any) => updateResult("loadWifiList", "Error: " + safeStringify(err))); + }} + /> + + + + {wifiList.length > 0 && ( + + Available Networks + {wifiList.map((item, index) => ( + { + setSsid(item.SSID); + addLog("Selected SSID: " + item.SSID); + }} + > + + {item.SSID || ''} + {item.level} dBm + + {item.BSSID} + {item.capabilities} + + ))} + + )} + + + + + + + { + addLog(`Connecting to ${ssid}...`); + if (password.length < 8) { + Alert.alert('密码需大于8位字符') + return + } else { + WifiManager.connectToProtectedSSID(ssid, password, false, false) + .then(() => updateResult("connectToProtectedSSID", "Connected to " + ssid)) + .catch((err: any) => updateResult("connectToProtectedSSID", "Error: " + safeStringify(err))); + } + + }} + /> + + + + + + + + + + { + WifiManager.disconnect() + .then((res: any) => updateResult("disconnect", "Disconnect: " + safeStringify(res))) + .catch((err: any) => updateResult("disconnect", "Error: " + safeStringify(err))); + }} + /> + + + + + + + + ); +}; + +const styles = StyleSheet.create({ + headerContainer: { + backgroundColor: COLORS.background, + padding: 10, + borderBottomWidth: 1, + borderBottomColor: COLORS.border, + elevation: 2, + zIndex: 100, + }, + headerTitle: { + fontSize: 20, + fontWeight: 'bold', + color: COLORS.text, + marginBottom: 10, + textAlign: 'center', + }, + inputCard: { + backgroundColor: COLORS.card, + borderRadius: 10, + padding: 10, + shadowColor: '#000', + shadowOffset: { width: 0, height: 2 }, + shadowOpacity: 0.1, + shadowRadius: 4, + elevation: 3, + }, + input: { + height: 44, + borderColor: COLORS.border, + borderWidth: 1, + borderRadius: 8, + marginBottom: 10, + paddingHorizontal: 12, + backgroundColor: '#FAFAFA', + fontSize: 16, + color: COLORS.text, + }, + testCaseContent: { + padding: 10, + }, + button: { + paddingVertical: 12, + paddingHorizontal: 20, + borderRadius: 8, + alignItems: 'center', + justifyContent: 'center', + elevation: 2, + shadowColor: '#000', + shadowOffset: { width: 0, height: 1 }, + shadowOpacity: 0.2, + shadowRadius: 2, + }, + buttonText: { + color: 'white', + fontSize: 16, + fontWeight: '600', + }, + resultContainer: { + marginTop: 10, + padding: 10, + backgroundColor: '#F8F9FA', + borderRadius: 6, + borderLeftWidth: 4, + borderLeftColor: COLORS.secondary, + }, + resultLabel: { + fontSize: 12, + color: COLORS.subText, + marginBottom: 4, + fontWeight: '600', + }, + resultText: { + fontSize: 14, + color: COLORS.text, + fontFamily: 'monospace', + }, + descriptionText: { + fontSize: 13, + color: '#666', + marginBottom: 10, + lineHeight: 18, + fontStyle: 'italic', + }, + wifiListContainer: { + padding: 10, + backgroundColor: COLORS.background, + }, + sectionTitle: { + fontSize: 18, + fontWeight: 'bold', + color: COLORS.text, + marginBottom: 10, + marginLeft: 5, + }, + wifiItem: { + padding: 15, + backgroundColor: COLORS.card, + borderRadius: 10, + marginBottom: 8, + shadowColor: '#000', + shadowOffset: { width: 0, height: 1 }, + shadowOpacity: 0.1, + shadowRadius: 2, + elevation: 2, + }, + wifiItemHeader: { + flexDirection: 'row', + justifyContent: 'space-between', + alignItems: 'center', + marginBottom: 4, + }, + wifiSSID: { + fontSize: 16, + fontWeight: 'bold', + color: COLORS.text, + }, + wifiLevel: { + fontSize: 14, + color: COLORS.success, + fontWeight: '600', + }, + wifiBSSID: { + fontSize: 12, + color: COLORS.subText, + marginBottom: 2, + }, + wifiDetails: { + fontSize: 11, + color: COLORS.subText, + fontStyle: 'italic', + }, +}); + + +``` +## Link + +此步骤为手动配置原生依赖项的指导。 + +首先需要使用 DevEco Studio 打开项目里的 HarmonyOS 工程 `harmony` + +### 1.在工程根目录的 `oh-package.json` 添加 overrides字段 + +```json +{ + ... + "overrides": { + "@rnoh/react-native-openharmony" : "./react_native_openharmony" + } + ... +} +``` + +### 2.引入原生端代码 + +目前有两种方法: + +1. 通过 har 包引入(在 IDE 完善相关功能后该方法会被遗弃,目前首选此方法); +2. 直接链接源码。 + +方法一:通过 har 包引入 (推荐) + +> [!TIP] har 包位于三方库安装路径的 `harmony` 文件夹下。 + +打开 `entry/oh-package.json5`,添加以下依赖 + +```json +"dependencies": { + "@rnoh/react-native-openharmony": "file:../react_native_openharmony", + "@react-native-ohos/react-native-wifi-reborn": "file:../../node_modules/@react-native-ohos/react-native-wifi-reborn/harmony/wifi_reborn.har" + } +``` + +点击右上角的 `sync` 按钮 + +或者在终端执行: + +```bash +cd entry +ohpm install +``` + +方法二:直接链接源码 + +> [!TIP] 如需使用直接链接源码,请参考[直接链接源码说明](/zh-cn/link-source-code.md) + + +### 4.配置 CMakeLists 和引入 turbo_log + +打开 entry/src/main/cpp/CMakeLists.txt,添加: + +```diff +include(FetchContent) +# BOOST +set(BOOST_ENABLE_CMAKE On) +FetchContent_Declare( + Boost + URL /7277/boost-1.82.0.tar.xz + OVERRIDE_FIND_PACKAGE) +project(rnapp) +cmake_minimum_required(VERSION 3.4.1) +set(CMAKE_SKIP_BUILD_RPATH TRUE) +set(RNOH_APP_DIR "${CMAKE_CURRENT_SOURCE_DIR}") +set(NODE_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../node_modules") ++ set(OH_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/../../../oh_modules") +set(RNOH_CPP_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../../oh_modules/@rnoh/react-native-openharmony/src/main/cpp") +set(RNOH_GENERATED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/generated") +set(LOG_VERBOSITY_LEVEL 1) +set(CMAKE_ASM_FLAGS "-Wno-error=unused-command-line-argument -Qunused-arguments") +set(CMAKE_CXX_FLAGS "-fstack-protector-strong -Wl,-z,relro,-z,now,-z,noexecstack -s -fPIE -pie") +set(WITH_HITRACE_SYSTRACE 1) # for other CMakeLists.txt files to use +add_compile_definitions(WITH_HITRACE_SYSTRACE) + + +add_subdirectory("${RNOH_CPP_DIR}" ./rn) + +# RNOH_BEGIN: manual_package_linking_1 +add_subdirectory("${OH_MODULES}/@react-native-ohos/react-native-gesture-handler/src/main/cpp" ./gesture-handler) ++ add_subdirectory("${OH_MODULES}/@react-native-ohos/react-native-wifi-reborn/src/main/cpp" ./wifi_reborn) +# RNOH_END: manual_package_linking_1 + +file(GLOB GENERATED_CPP_FILES "./generated/*.cpp") # this line is needed by codegen v1 +add_library(rnoh_app SHARED + ${GENERATED_CPP_FILES} + "./PackageProvider.cpp" + "${RNOH_CPP_DIR}/RNOHAppNapiBridge.cpp" +) +target_link_libraries(rnoh_app PUBLIC rnoh) + +# RNOH_BEGIN: manual_package_linking_2 +target_link_libraries(rnoh_app PUBLIC rnoh_gesture_handler) ++ target_link_libraries(rnoh_app PUBLIC rnoh_wifi_reborn) +# RNOH_END: manual_package_linking_2 + +``` + +### 4.Import the TurboLogPackage on the ArkTS side + +打开 `entry/src/main/cpp/PackageProvider.cpp`,添加: + +```diff +#include "RNOH/PackageProvider.h" +#include "generated/RNOHGeneratedPackage.h" +#include "SamplePackage.h" ++ #include "WifiRebornPackage.h" + +using namespace rnoh; + +std::vector> PackageProvider::getPackages(Package::Context ctx) { + return { + std::make_shared(ctx), + std::make_shared(ctx), ++ std::make_shared(ctx), + }; +} +``` + +### 5.运行 + +点击右上角的 `sync` 按钮 + +或者在终端执行: + +```bash +cd entry +ohpm install +``` + +然后编译、运行即可。 + +## 约束与限制 + +### 兼容性 + +本文档内容基于以下版本验证通过: +1. RNOH:0.72.90; SDK:HarmonyOS NEXT Developer DB3; IDE: DevEco Studio: 5.0.5.220; ROM:NEXT.0.0.105; +2. RNOH:0.77.18; SDK:HarmonyOS 6.0.0 Release; IDE: DevEco Studio 6.0.0.858; ROM:6.0.0.112; + +### 权限要求 + +以下权限中有`system_basic` 权限,而默认的应用权限是 `normal` ,只能使用 `normal` 等级的权限,所以可能会在安装hap包时报错**9568289**,请参考 [文档](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/bm-tool-V5#ZH-CN_TOPIC_0000001884757326__%E5%AE%89%E8%A3%85hap%E6%97%B6%E6%8F%90%E7%A4%BAcode9568289-error-install-failed-due-to-grant-request-permissions-failed) 修改应用等级为 `system_basic` + +#### 在 entry 目录下的module.json5中添加权限 + +打开 `entry/src/main/module.json5`,添加: + +```diff +... +"requestPermissions": [ + { + "name": "ohos.permission.GET_WIFI_INFO", + "reason": "$string:wifi_info_reason", + "usedScene": { + "abilities": [], + "when": "inuse" + } + }, + { + "name": "ohos.permission.SET_WIFI_INFO", + "reason": "$string:wifi_set_reason", + "usedScene": { + "abilities": [], + "when": "inuse" + } + }, + { + "name": "ohos.permission.LOCATION", + "reason": "$string:location_reason", + "usedScene": { + "abilities": [], + "when": "inuse" + } + }, + { + "name": "ohos.permission.APPROXIMATELY_LOCATION", + "reason": "$string:location_approx_reason", + "usedScene": { + "abilities": [], + "when": "inuse" + } + } + ], +``` + +#### 在 entry 目录下添加申请以上权限的原因 + +打开 `entry/src/main/resources/base/element/string.json`,添加: + +```diff +... +{ + "string": [ + { + "name": "wifi_info_reason", + "value": "需要获取WiFi信息以显示当前连接的网络状态" + }, + { + "name": "wifi_set_reason", + "value": "需要配置WiFi网络以连接到指定的无线网络" + }, + { + "name": "wifi_manage_reason", + "value": "需要管理WiFi连接以提供完整的网络控制功能" + }, + { + "name": "wifi_mac_reason", + "value": "需要获取WiFi MAC地址用于网络识别" + }, + { + "name": "location_reason", + "value": "需要位置权限以扫描附近的WiFi网络(系统要求)" + }, + { + "name": "location_approx_reason", + "value": "需要大致位置权限以扫描WiFi网络" + }, + { + "name": "module_desc", + "value": "React Native WiFi Manager - WiFi网络管理模块" + } + ] +} + +``` + +## 属性 + +> [!TIP] "Platform"列表示该属性在原三方库上支持的平台。 + +> [!TIP] "HarmonyOS Support"列为 yes 表示 HarmonyOS 平台支持该属性;no 则表示不支持;partially 表示部分支持。使用方法跨平台一致,效果对标 iOS 或 Android 的效果。droid 的效果。 + +**wifi-reborn**:适用于 React Native的 WiFi 管理第三方库,主要用于在应用中实现与设备 WiFi 功能相关的各种操作。 + +| Name | Description | Type | Required | Platform | HarmonyOS Support | +|-----------------|----------------------|----------|----------|-------------|-------------------| +| connectToProtectSSID | 连接到受保护的SSID | function | no | Android/IOS | yes | +| suggestWifiNetwork | 向移动设备系统推荐/提示指定可见的 WIFI 网络 | function | no | Android/IOS | yes | +| connectToProtectedWifiSSID | 连接到名为SSID的受保护的 WIFI | function | no | Android/IOS | yes | +| getCurrentWifiSSID | 返回当前WIFI网络的SSID | function | no | Android/IOS | yes | +| connectToSSID | 连接到SSID | function | no | IOS | yes | +| connectToSSIDPrefix | 连接到特定前缀的SSID | function | no | IOS | yes | +| disconnectFromSSID | 断开与SSID的连接 | function | no | IOS | yes | +| connectToProtectedSSIDOnce | 连接到受保护的SSID一次 | function | no | IOS | no | +| connectToProtectedSSIDPrefix | 连接到受保护的特定前缀的SSID | function | no | IOS | yes | +| connectToProtectedSSIDPrefixOnce | 连接到受保护的特定前缀的SSID一次 | function | no | IOS | no | +| loadWifiList | 返回附近WIFI网络列表 | function | no | Android | yes | +| reScanAndLoadWifiList | 重新扫描周边可见 WiFi 网络,并加载返回完整的 WiFi 列表数据 | function | no | Android | yes | +| isEnabled | 检查 WIFI 是否已开启 | function | no | Android | yes | +| setEnabled | 在设备上设置 WIFI 开启或关闭 | function | no | Android | yes | +| connectionStatus | 当前设备连接 WIFI 的状态,已连接返回true | function | no | Android | yes | +| disconnect | 断开当前连接的 WIFI | function | no | Android | yes | +| getBSSID | 返回当前连接 WIFI 的BSSID | function | no | Android | yes | +| getCurrentSignalStrength | 返回当前连接 WIFI 的RSSI(信号强度) | function | no | Android | yes | +| getFrequency | 返回当前连接的 WIFI 的信号频率 | function | no | Android | yes | +| getIP | 返回当前连接 WIFI 的IP地址 | function | no | Android | yes | +| isRemoveWifiNetwork | 移除设备中已保存配置的指定 WiFi 网络 | function | no | Android | yes | +| forceWifiUsage | 强制当前应用的网络请求走设备已连接的WIFI通道,忽略移动数据 | function | no | Android | yes | +| forceWifiUsageWithOptions | 强制当前应用的网络请求走设备已连接的WIFI通道,忽略移动数据(可传入配置对象) | function | no | Android | yes | + + +## 静态方法 + +## 遗留问题 + +## 其他 + +•connectToProtectedSSIDOnce和connectToProtectedSSIDPrefixOnce方法无法实现,这两个方法是专门为ios平台设计的,在ios系统中使用了NEHotspotConfigurationManager传递joinOnce参数来实现一次连接功能,鸿蒙侧不支持此功能。 + + + +## 开源协议 + +本项目基于 [The MIT License (MIT)](https://github.com/JuanSeBestia/react-native-wifi-reborn/blob/master/LICENSE) ,请自由地享受和参与开源。 -- Gitee From 61bcc786ff3d2581a88700f6de57e6577e67f9fb Mon Sep 17 00:00:00 2001 From: ZZZH Date: Tue, 6 Jan 2026 11:53:14 +0800 Subject: [PATCH 06/17] =?UTF-8?q?docs:=20[Issues:=20#IDHIT7]=E4=BF=AE?= =?UTF-8?q?=E6=94=B9react-native-wifi-reborn=E7=9A=84=E4=B8=AD=E8=8B=B1?= =?UTF-8?q?=E6=96=87=E6=8C=87=E5=AF=BC=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- en/react-native-wifi-reborn.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/en/react-native-wifi-reborn.md b/en/react-native-wifi-reborn.md index 651d4a3b..0007f032 100644 --- a/en/react-native-wifi-reborn.md +++ b/en/react-native-wifi-reborn.md @@ -139,7 +139,7 @@ export const TurboLogDemoTest = () => { - + { @@ -159,7 +159,7 @@ export const TurboLogDemoTest = () => { - + { @@ -199,13 +199,13 @@ export const TurboLogDemoTest = () => { - + { addLog(`Connecting to ${ssid}...`); if (password.length < 8) { - Alert.alert('密码需大于8位字符') + Alert.alert('Password must be greater than 8 characters') return } else { WifiManager.connectToProtectedSSID(ssid, password, false, false) @@ -223,7 +223,7 @@ export const TurboLogDemoTest = () => { - + Date: Tue, 6 Jan 2026 12:01:11 +0800 Subject: [PATCH 07/17] =?UTF-8?q?docs:=20[Issues:=20#IDHIT7]=E4=BF=AE?= =?UTF-8?q?=E6=94=B9react-native-wifi-reborn=E7=9A=84=E4=B8=AD=E8=8B=B1?= =?UTF-8?q?=E6=96=87=E6=8C=87=E5=AF=BC=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- en/react-native-wifi-reborn.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/en/react-native-wifi-reborn.md b/en/react-native-wifi-reborn.md index 0007f032..aeed1eb7 100644 --- a/en/react-native-wifi-reborn.md +++ b/en/react-native-wifi-reborn.md @@ -576,31 +576,31 @@ Open 'entry/src/main/resources/base/element/string. json' and add: "string": [ { "name": "wifi_info_reason", - "value": "需要获取WiFi信息以显示当前连接的网络状态" + "value": "Need to obtain WiFi information to display the current network status of the connection" }, { "name": "wifi_set_reason", - "value": "需要配置WiFi网络以连接到指定的无线网络" + "value": "Need to configure WiFi network to connect to the specified wireless network" }, { "name": "wifi_manage_reason", - "value": "需要管理WiFi连接以提供完整的网络控制功能" + "value": "Need to manage WiFi connections to provide complete network control functionality" }, { "name": "wifi_mac_reason", - "value": "需要获取WiFi MAC地址用于网络识别" + "value": "Need to obtain WiFi MAC address for network identification" }, { "name": "location_reason", - "value": "需要位置权限以扫描附近的WiFi网络(系统要求)" + "value": "Location permission is required to scan nearby WiFi networks (system requirement)" }, { "name": "location_approx_reason", - "value": "需要大致位置权限以扫描WiFi网络" + "value": "Need approximate location permission to scan WiFi networks" }, { "name": "module_desc", - "value": "React Native WiFi Manager - WiFi网络管理模块" + "value": "React Native WiFi Manager - WiFi Network Management Module" } ] } -- Gitee From b772da9cf1b0527660cd5b5ba296511aa40ea2be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=88=9F=E5=87=BD?= Date: Tue, 6 Jan 2026 05:42:13 +0000 Subject: [PATCH 08/17] =?UTF-8?q?Revert=20"docs:=20[Issues:=20#IDHIT7]?= =?UTF-8?q?=E4=BF=AE=E6=94=B9react-native-wifi-reborn=E7=9A=84=E4=B8=AD?= =?UTF-8?q?=E8=8B=B1=E6=96=87=E6=8C=87=E5=AF=BC=E6=96=87=E6=A1=A3"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit e366062aacd09a07e2fcaa147f59e16e1298ca84. --- en/react-native-wifi-reborn.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/en/react-native-wifi-reborn.md b/en/react-native-wifi-reborn.md index aeed1eb7..0007f032 100644 --- a/en/react-native-wifi-reborn.md +++ b/en/react-native-wifi-reborn.md @@ -576,31 +576,31 @@ Open 'entry/src/main/resources/base/element/string. json' and add: "string": [ { "name": "wifi_info_reason", - "value": "Need to obtain WiFi information to display the current network status of the connection" + "value": "需要获取WiFi信息以显示当前连接的网络状态" }, { "name": "wifi_set_reason", - "value": "Need to configure WiFi network to connect to the specified wireless network" + "value": "需要配置WiFi网络以连接到指定的无线网络" }, { "name": "wifi_manage_reason", - "value": "Need to manage WiFi connections to provide complete network control functionality" + "value": "需要管理WiFi连接以提供完整的网络控制功能" }, { "name": "wifi_mac_reason", - "value": "Need to obtain WiFi MAC address for network identification" + "value": "需要获取WiFi MAC地址用于网络识别" }, { "name": "location_reason", - "value": "Location permission is required to scan nearby WiFi networks (system requirement)" + "value": "需要位置权限以扫描附近的WiFi网络(系统要求)" }, { "name": "location_approx_reason", - "value": "Need approximate location permission to scan WiFi networks" + "value": "需要大致位置权限以扫描WiFi网络" }, { "name": "module_desc", - "value": "React Native WiFi Manager - WiFi Network Management Module" + "value": "React Native WiFi Manager - WiFi网络管理模块" } ] } -- Gitee From fe2d2e17475fccf74251c306472eb1da1d9bdbb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=88=9F=E5=87=BD?= Date: Tue, 6 Jan 2026 05:42:38 +0000 Subject: [PATCH 09/17] =?UTF-8?q?Revert=20"Revert=20"docs:=20[Issues:=20#I?= =?UTF-8?q?DHIT7]=E4=BF=AE=E6=94=B9react-native-wifi-reborn=E7=9A=84?= =?UTF-8?q?=E4=B8=AD=E8=8B=B1=E6=96=87=E6=8C=87=E5=AF=BC=E6=96=87=E6=A1=A3?= =?UTF-8?q?""?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit b772da9cf1b0527660cd5b5ba296511aa40ea2be. --- en/react-native-wifi-reborn.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/en/react-native-wifi-reborn.md b/en/react-native-wifi-reborn.md index 0007f032..aeed1eb7 100644 --- a/en/react-native-wifi-reborn.md +++ b/en/react-native-wifi-reborn.md @@ -576,31 +576,31 @@ Open 'entry/src/main/resources/base/element/string. json' and add: "string": [ { "name": "wifi_info_reason", - "value": "需要获取WiFi信息以显示当前连接的网络状态" + "value": "Need to obtain WiFi information to display the current network status of the connection" }, { "name": "wifi_set_reason", - "value": "需要配置WiFi网络以连接到指定的无线网络" + "value": "Need to configure WiFi network to connect to the specified wireless network" }, { "name": "wifi_manage_reason", - "value": "需要管理WiFi连接以提供完整的网络控制功能" + "value": "Need to manage WiFi connections to provide complete network control functionality" }, { "name": "wifi_mac_reason", - "value": "需要获取WiFi MAC地址用于网络识别" + "value": "Need to obtain WiFi MAC address for network identification" }, { "name": "location_reason", - "value": "需要位置权限以扫描附近的WiFi网络(系统要求)" + "value": "Location permission is required to scan nearby WiFi networks (system requirement)" }, { "name": "location_approx_reason", - "value": "需要大致位置权限以扫描WiFi网络" + "value": "Need approximate location permission to scan WiFi networks" }, { "name": "module_desc", - "value": "React Native WiFi Manager - WiFi网络管理模块" + "value": "React Native WiFi Manager - WiFi Network Management Module" } ] } -- Gitee From f270915157c9f6c625c2c537bb2312e98923d249 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=88=9F=E5=87=BD?= Date: Tue, 6 Jan 2026 05:43:08 +0000 Subject: [PATCH 10/17] =?UTF-8?q?Revert=20"Revert=20"Revert=20"docs:=20[Is?= =?UTF-8?q?sues:=20#IDHIT7]=E4=BF=AE=E6=94=B9react-native-wifi-reborn?= =?UTF-8?q?=E7=9A=84=E4=B8=AD=E8=8B=B1=E6=96=87=E6=8C=87=E5=AF=BC=E6=96=87?= =?UTF-8?q?=E6=A1=A3"""?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit fe2d2e17475fccf74251c306472eb1da1d9bdbb4. --- en/react-native-wifi-reborn.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/en/react-native-wifi-reborn.md b/en/react-native-wifi-reborn.md index aeed1eb7..0007f032 100644 --- a/en/react-native-wifi-reborn.md +++ b/en/react-native-wifi-reborn.md @@ -576,31 +576,31 @@ Open 'entry/src/main/resources/base/element/string. json' and add: "string": [ { "name": "wifi_info_reason", - "value": "Need to obtain WiFi information to display the current network status of the connection" + "value": "需要获取WiFi信息以显示当前连接的网络状态" }, { "name": "wifi_set_reason", - "value": "Need to configure WiFi network to connect to the specified wireless network" + "value": "需要配置WiFi网络以连接到指定的无线网络" }, { "name": "wifi_manage_reason", - "value": "Need to manage WiFi connections to provide complete network control functionality" + "value": "需要管理WiFi连接以提供完整的网络控制功能" }, { "name": "wifi_mac_reason", - "value": "Need to obtain WiFi MAC address for network identification" + "value": "需要获取WiFi MAC地址用于网络识别" }, { "name": "location_reason", - "value": "Location permission is required to scan nearby WiFi networks (system requirement)" + "value": "需要位置权限以扫描附近的WiFi网络(系统要求)" }, { "name": "location_approx_reason", - "value": "Need approximate location permission to scan WiFi networks" + "value": "需要大致位置权限以扫描WiFi网络" }, { "name": "module_desc", - "value": "React Native WiFi Manager - WiFi Network Management Module" + "value": "React Native WiFi Manager - WiFi网络管理模块" } ] } -- Gitee From 8a2adc49fb8b119a9057db4871f212feac519121 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=88=9F=E5=87=BD?= Date: Tue, 6 Jan 2026 05:43:34 +0000 Subject: [PATCH 11/17] =?UTF-8?q?Revert=20"Revert=20"Revert=20"Revert=20"d?= =?UTF-8?q?ocs:=20[Issues:=20#IDHIT7]=E4=BF=AE=E6=94=B9react-native-wifi-r?= =?UTF-8?q?eb=E2=80=A6"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit f270915157c9f6c625c2c537bb2312e98923d249. --- en/react-native-wifi-reborn.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/en/react-native-wifi-reborn.md b/en/react-native-wifi-reborn.md index 0007f032..aeed1eb7 100644 --- a/en/react-native-wifi-reborn.md +++ b/en/react-native-wifi-reborn.md @@ -576,31 +576,31 @@ Open 'entry/src/main/resources/base/element/string. json' and add: "string": [ { "name": "wifi_info_reason", - "value": "需要获取WiFi信息以显示当前连接的网络状态" + "value": "Need to obtain WiFi information to display the current network status of the connection" }, { "name": "wifi_set_reason", - "value": "需要配置WiFi网络以连接到指定的无线网络" + "value": "Need to configure WiFi network to connect to the specified wireless network" }, { "name": "wifi_manage_reason", - "value": "需要管理WiFi连接以提供完整的网络控制功能" + "value": "Need to manage WiFi connections to provide complete network control functionality" }, { "name": "wifi_mac_reason", - "value": "需要获取WiFi MAC地址用于网络识别" + "value": "Need to obtain WiFi MAC address for network identification" }, { "name": "location_reason", - "value": "需要位置权限以扫描附近的WiFi网络(系统要求)" + "value": "Location permission is required to scan nearby WiFi networks (system requirement)" }, { "name": "location_approx_reason", - "value": "需要大致位置权限以扫描WiFi网络" + "value": "Need approximate location permission to scan WiFi networks" }, { "name": "module_desc", - "value": "React Native WiFi Manager - WiFi网络管理模块" + "value": "React Native WiFi Manager - WiFi Network Management Module" } ] } -- Gitee From 0a1291160ecbdca6b09eb3b675bbe1200c512e4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=88=9F=E5=87=BD?= Date: Tue, 6 Jan 2026 05:43:51 +0000 Subject: [PATCH 12/17] =?UTF-8?q?Revert=20"Revert=20"Revert=20"Revert=20"R?= =?UTF-8?q?evert=20"docs:=20[Issues:=20#IDHIT7]=E4=BF=AE=E6=94=B9react-nat?= =?UTF-8?q?ive-wifi-reb=E2=80=A6""?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 8a2adc49fb8b119a9057db4871f212feac519121. --- en/react-native-wifi-reborn.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/en/react-native-wifi-reborn.md b/en/react-native-wifi-reborn.md index aeed1eb7..0007f032 100644 --- a/en/react-native-wifi-reborn.md +++ b/en/react-native-wifi-reborn.md @@ -576,31 +576,31 @@ Open 'entry/src/main/resources/base/element/string. json' and add: "string": [ { "name": "wifi_info_reason", - "value": "Need to obtain WiFi information to display the current network status of the connection" + "value": "需要获取WiFi信息以显示当前连接的网络状态" }, { "name": "wifi_set_reason", - "value": "Need to configure WiFi network to connect to the specified wireless network" + "value": "需要配置WiFi网络以连接到指定的无线网络" }, { "name": "wifi_manage_reason", - "value": "Need to manage WiFi connections to provide complete network control functionality" + "value": "需要管理WiFi连接以提供完整的网络控制功能" }, { "name": "wifi_mac_reason", - "value": "Need to obtain WiFi MAC address for network identification" + "value": "需要获取WiFi MAC地址用于网络识别" }, { "name": "location_reason", - "value": "Location permission is required to scan nearby WiFi networks (system requirement)" + "value": "需要位置权限以扫描附近的WiFi网络(系统要求)" }, { "name": "location_approx_reason", - "value": "Need approximate location permission to scan WiFi networks" + "value": "需要大致位置权限以扫描WiFi网络" }, { "name": "module_desc", - "value": "React Native WiFi Manager - WiFi Network Management Module" + "value": "React Native WiFi Manager - WiFi网络管理模块" } ] } -- Gitee From 37493e5814f8390739feae9ae7cb68ae763ed24c Mon Sep 17 00:00:00 2001 From: ZZZH Date: Tue, 6 Jan 2026 14:12:20 +0800 Subject: [PATCH 13/17] =?UTF-8?q?docs:=20[Issues:=20#IDHIT7]=E4=BF=AE?= =?UTF-8?q?=E6=94=B9react-native-wifi-reborn=E7=9A=84=E4=B8=AD=E8=8B=B1?= =?UTF-8?q?=E6=96=87=E6=8C=87=E5=AF=BC=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- en/react-native-wifi-reborn.md | 1 - zh-cn/react-native-wifi-reborn.md | 1 - 2 files changed, 2 deletions(-) diff --git a/en/react-native-wifi-reborn.md b/en/react-native-wifi-reborn.md index aeed1eb7..28f17879 100644 --- a/en/react-native-wifi-reborn.md +++ b/en/react-native-wifi-reborn.md @@ -604,7 +604,6 @@ Open 'entry/src/main/resources/base/element/string. json' and add: } ] } - ``` ## Attributes diff --git a/zh-cn/react-native-wifi-reborn.md b/zh-cn/react-native-wifi-reborn.md index 2bd1c4ac..f494350f 100644 --- a/zh-cn/react-native-wifi-reborn.md +++ b/zh-cn/react-native-wifi-reborn.md @@ -605,7 +605,6 @@ ohpm install } ] } - ``` ## 属性 -- Gitee From d65c25a746a91f37d275d65787319bf879442ca8 Mon Sep 17 00:00:00 2001 From: ZZZH Date: Tue, 6 Jan 2026 16:14:13 +0800 Subject: [PATCH 14/17] =?UTF-8?q?docs:=20[Issues:=20#IDHIT7]=E4=BF=AE?= =?UTF-8?q?=E6=94=B9react-native-wifi-reborn=E7=9A=84=E4=B8=AD=E8=8B=B1?= =?UTF-8?q?=E6=96=87=E6=8C=87=E5=AF=BC=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- en/react-native-wifi-reborn.md | 657 ++++++++++++++++++++++++++++++ zh-cn/react-native-wifi-reborn.md | 657 ++++++++++++++++++++++++++++++ 2 files changed, 1314 insertions(+) create mode 100644 en/react-native-wifi-reborn.md create mode 100644 zh-cn/react-native-wifi-reborn.md diff --git a/en/react-native-wifi-reborn.md b/en/react-native-wifi-reborn.md new file mode 100644 index 00000000..28f17879 --- /dev/null +++ b/en/react-native-wifi-reborn.md @@ -0,0 +1,657 @@ +> Template Version: v0.2.2 + +

+

react-native-wifi-reborn

+

+ +Please check the release information of the corresponding version at the third-party library's Releases page: + +| Third-Party Library Version | Release Information | Supported RN Version | +| --------------------------- | --------------------------------------------------------------- | -------------------- | +| 0.6.1 | [@react-native-ohos/react-native-wifi-reborn Releases](https://github.com/react-native-oh-library/react-native-wifi-reborn/releases) | 0.72 | +| 0.7.0 | [@react-native-ohos/react-native-wifi-reborn Releases](https://github.com/react-native-oh-library/react-native-wifi-reborn/releases) | 0.77 | + +> [!TIP] [GitHub Address](https://github.com/react-native-oh-library/react-native-wifi-reborn) + +## Installation and Usage + +Navigate to the project directory and enter the following command: + + + + +#### npm + +```bash +npm install @react-native-ohos/react-native-wifi-reborn +``` + +#### yarn + +```bash +yarn add @react-native-ohos/react-native-wifi-reborn +``` + + + +The following code demonstrates the basic usage scenarios of this library: + +> [!WARNING] The library name used in the import remains unchanged. +### wifi-reborn example +``` js +import React, { useState } from 'react'; +import { ScrollView, StyleSheet, Text, TouchableOpacity, View, TextInput, Alert } from 'react-native'; +import { Tester, TestSuite, TestCase } from '@rnoh/testerino'; +import WifiManager from 'react-native-wifi-reborn'; +import RTNPermissions, { Permission } from "react-native-permissions"; + +const permissionNormal: Permission[] = [ + 'ohos.permission.GET_WIFI_INFO', + 'ohos.permission.SET_WIFI_INFO', + 'ohos.permission.LOCATION', + 'ohos.permission.MANAGE_WIFI_CONNECTION', + 'ohos.permission.GET_WIFI_LOCAL_MAC', + 'ohos.permission.APPROXIMATELY_LOCATION', +]; + +const COLORS = { + primary: '#007AFF', + secondary: '#5856D6', + success: '#4CD964', + background: '#F2F2F7', + card: '#FFFFFF', + text: '#000000', + subText: '#8E8E93', + border: '#C7C7CC', + error: '#FF3B30', +}; + +const CustomButton = ({ title, onPress, color = COLORS.primary }: { title: string, onPress: () => void, color?: string }) => ( + + {title} + +); + +const ResultArea = ({ text }: { text: string }) => { + if (!text) return null; + return ( + + Result: + {text} + + ); +}; + +const Description = ({ text }: { text: string }) => ( + {text} +); + +export const TurboLogDemoTest = () => { + const [wifiList, setWifiList] = useState([]); + const [ssid, setSsid] = useState(''); + const [password, setPassword] = useState(''); + const [log, setLog] = useState(''); + const [results, setResults] = useState<{ [key: string]: string }>({}); + + const addLog = (msg: string) => { + console.info(msg); + setLog(prev => msg + '\n' + prev); + }; + + const updateResult = (key: string, value: string) => { + setResults(prev => ({ ...prev, [key]: value })); + addLog(`${key}: ${value}`); + }; + + const safeStringify = (val: any) => { + if (typeof val === 'string') return val; + try { + return JSON.stringify(val, null, 2); + } catch (e) { + return String(val); + } + }; + + return ( + + + + Wifi Manager Demo + + + + + + + + + + + { + try { + let requestMultiple = await RTNPermissions.requestMultiple(permissionNormal); + updateResult("Permissions", safeStringify(requestMultiple)); + } catch (e) { + updateResult("Permissions", "Error: " + safeStringify(e)); + } + }} + /> + + + + + + + + + + { + WifiManager.loadWifiList().then((list: any) => { + updateResult("loadWifiList", "Loaded " + list.length + " networks"); + setWifiList(list); + }).catch((err: any) => updateResult("loadWifiList", "Error: " + safeStringify(err))); + }} + /> + + + + {wifiList.length > 0 && ( + + Available Networks + {wifiList.map((item, index) => ( + { + setSsid(item.SSID); + addLog("Selected SSID: " + item.SSID); + }} + > + + {item.SSID || ''} + {item.level} dBm + + {item.BSSID} + {item.capabilities} + + ))} + + )} + + + + + + + { + addLog(`Connecting to ${ssid}...`); + if (password.length < 8) { + Alert.alert('Password must be greater than 8 characters') + return + } else { + WifiManager.connectToProtectedSSID(ssid, password, false, false) + .then(() => updateResult("connectToProtectedSSID", "Connected to " + ssid)) + .catch((err: any) => updateResult("connectToProtectedSSID", "Error: " + safeStringify(err))); + } + + }} + /> + + + + + + + + + + { + WifiManager.disconnect() + .then((res: any) => updateResult("disconnect", "Disconnect: " + safeStringify(res))) + .catch((err: any) => updateResult("disconnect", "Error: " + safeStringify(err))); + }} + /> + + + + + + + + ); +}; + +const styles = StyleSheet.create({ + headerContainer: { + backgroundColor: COLORS.background, + padding: 10, + borderBottomWidth: 1, + borderBottomColor: COLORS.border, + elevation: 2, + zIndex: 100, + }, + headerTitle: { + fontSize: 20, + fontWeight: 'bold', + color: COLORS.text, + marginBottom: 10, + textAlign: 'center', + }, + inputCard: { + backgroundColor: COLORS.card, + borderRadius: 10, + padding: 10, + shadowColor: '#000', + shadowOffset: { width: 0, height: 2 }, + shadowOpacity: 0.1, + shadowRadius: 4, + elevation: 3, + }, + input: { + height: 44, + borderColor: COLORS.border, + borderWidth: 1, + borderRadius: 8, + marginBottom: 10, + paddingHorizontal: 12, + backgroundColor: '#FAFAFA', + fontSize: 16, + color: COLORS.text, + }, + testCaseContent: { + padding: 10, + }, + button: { + paddingVertical: 12, + paddingHorizontal: 20, + borderRadius: 8, + alignItems: 'center', + justifyContent: 'center', + elevation: 2, + shadowColor: '#000', + shadowOffset: { width: 0, height: 1 }, + shadowOpacity: 0.2, + shadowRadius: 2, + }, + buttonText: { + color: 'white', + fontSize: 16, + fontWeight: '600', + }, + resultContainer: { + marginTop: 10, + padding: 10, + backgroundColor: '#F8F9FA', + borderRadius: 6, + borderLeftWidth: 4, + borderLeftColor: COLORS.secondary, + }, + resultLabel: { + fontSize: 12, + color: COLORS.subText, + marginBottom: 4, + fontWeight: '600', + }, + resultText: { + fontSize: 14, + color: COLORS.text, + fontFamily: 'monospace', + }, + descriptionText: { + fontSize: 13, + color: '#666', + marginBottom: 10, + lineHeight: 18, + fontStyle: 'italic', + }, + wifiListContainer: { + padding: 10, + backgroundColor: COLORS.background, + }, + sectionTitle: { + fontSize: 18, + fontWeight: 'bold', + color: COLORS.text, + marginBottom: 10, + marginLeft: 5, + }, + wifiItem: { + padding: 15, + backgroundColor: COLORS.card, + borderRadius: 10, + marginBottom: 8, + shadowColor: '#000', + shadowOffset: { width: 0, height: 1 }, + shadowOpacity: 0.1, + shadowRadius: 2, + elevation: 2, + }, + wifiItemHeader: { + flexDirection: 'row', + justifyContent: 'space-between', + alignItems: 'center', + marginBottom: 4, + }, + wifiSSID: { + fontSize: 16, + fontWeight: 'bold', + color: COLORS.text, + }, + wifiLevel: { + fontSize: 14, + color: COLORS.success, + fontWeight: '600', + }, + wifiBSSID: { + fontSize: 12, + color: COLORS.subText, + marginBottom: 2, + }, + wifiDetails: { + fontSize: 11, + color: COLORS.subText, + fontStyle: 'italic', + }, +}); + + +``` +## Link + +This step provides guidance for manually configuring native dependencies. + +First, use DevEco Studio to open the HarmonyOS project `harmony` in your project. + +### 1. Add the `overrides` field to the `oh-package.json` file in the root directory of the project. + +```json +{ + ... + "overrides": { + "@rnoh/react-native-openharmony" : "./react_native_openharmony" + } + ... +} +``` + +### 2. Introduce Native Code + +Currently, there are two methods: + +1. Import via har package (this method will be deprecated after the IDE improves related features; currently, it is the preferred method); +2. Directly link the source code. + +**Method 1: Import via har package (Recommended)** + +> [!TIP] The har package is located in the `harmony` folder under the third-party library installation path. + +Open `entry/oh-package.json5` and add the following dependencies. + +```json +"dependencies": { + "@rnoh/react-native-openharmony": "file:../react_native_openharmony", + "@react-native-ohos/react-native-wifi-reborn": "file:../../node_modules/@react-native-ohos/react-native-wifi-reborn/harmony/wifi_reborn.har" + } +``` + +Click the `sync` button in the top right corner + +Or execute in the terminal: + +```bash +cd entry +ohpm install +``` + +Method 2: Directly link the source code + +> [!TIP] If you need to use direct source code linking, refer to [Direct Source Code Linking Instructions](/zh-cn/link-source-code.md) + + +### 4. Configure CMakeLists and introduce turbo_log + +Open `entry/src/main/cpp/CMakeLists.txt` and add: + +```diff +include(FetchContent) +# BOOST +set(BOOST_ENABLE_CMAKE On) +FetchContent_Declare( + Boost + URL /7277/boost-1.82.0.tar.xz + OVERRIDE_FIND_PACKAGE) +project(rnapp) +cmake_minimum_required(VERSION 3.4.1) +set(CMAKE_SKIP_BUILD_RPATH TRUE) +set(RNOH_APP_DIR "${CMAKE_CURRENT_SOURCE_DIR}") +set(NODE_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../node_modules") ++ set(OH_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/../../../oh_modules") +set(RNOH_CPP_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../../oh_modules/@rnoh/react-native-openharmony/src/main/cpp") +set(RNOH_GENERATED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/generated") +set(LOG_VERBOSITY_LEVEL 1) +set(CMAKE_ASM_FLAGS "-Wno-error=unused-command-line-argument -Qunused-arguments") +set(CMAKE_CXX_FLAGS "-fstack-protector-strong -Wl,-z,relro,-z,now,-z,noexecstack -s -fPIE -pie") +set(WITH_HITRACE_SYSTRACE 1) # for other CMakeLists.txt files to use +add_compile_definitions(WITH_HITRACE_SYSTRACE) + + +add_subdirectory("${RNOH_CPP_DIR}" ./rn) + +# RNOH_BEGIN: manual_package_linking_1 +add_subdirectory("${OH_MODULES}/@react-native-ohos/react-native-gesture-handler/src/main/cpp" ./gesture-handler) ++ add_subdirectory("${OH_MODULES}/@react-native-ohos/react-native-wifi-reborn/src/main/cpp" ./wifi_reborn) +# RNOH_END: manual_package_linking_1 + +file(GLOB GENERATED_CPP_FILES "./generated/*.cpp") # this line is needed by codegen v1 +add_library(rnoh_app SHARED + ${GENERATED_CPP_FILES} + "./PackageProvider.cpp" + "${RNOH_CPP_DIR}/RNOHAppNapiBridge.cpp" +) +target_link_libraries(rnoh_app PUBLIC rnoh) + +# RNOH_BEGIN: manual_package_linking_2 +target_link_libraries(rnoh_app PUBLIC rnoh_gesture_handler) ++ target_link_libraries(rnoh_app PUBLIC rnoh_wifi_reborn) +# RNOH_END: manual_package_linking_2 + +``` + +### 4.Import the TurboLogPackage on the ArkTS side + +打开 `entry/src/main/cpp/PackageProvider.cpp`,添加: + +```diff +#include "RNOH/PackageProvider.h" +#include "generated/RNOHGeneratedPackage.h" +#include "SamplePackage.h" ++ #include "WifiRebornPackage.h" + +using namespace rnoh; + +std::vector> PackageProvider::getPackages(Package::Context ctx) { + return { + std::make_shared(ctx), + std::make_shared(ctx), ++ std::make_shared(ctx), + }; +} +``` + +### 5. Run + +Click the `sync` button in the top right corner. + +Or execute the following in the terminal: + +```bash +cd entry +ohpm install +``` + +Then compile and run. + +## Constraints and Limitations + +### Compatibility + +The content of this document has been verified with the following versions: +1. RNOH: 0.72.90; SDK: HarmonyOS NEXT Developer DB3; IDE: DevEco Studio: 5.0.5.220; ROM: NEXT.0.0.105; +2. RNOH: 0.77.18; SDK: HarmonyOS 6.0.0 Release; IDE: DevEco Studio 6.0.0.858; ROM: 6.0.0.112; + +### Permission requirements +Among the following permissions, there is a 'system_masic' permission, while the default application permission is' normal ', which can only be used at the' normal 'level. Therefore, when installing the HAP package, an error may occur * * 9568289 * *, please refer to the [document]( https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/bm-tool-V5#ZH -CN_TOPIC_0000001884757326__%E5%AE%89%E8%A3%85hap%E6%97%B6%E6%8F%90%E7%A4%BAcode9568289-error-install-failed-due-to-grant-request-permissions-failed) Change the application level to 'system_masic'` + +#### Add permissions to module.json5 in the entry directory + +Open 'entry/src/main/module. json5' and add: + +```diff +... +"requestPermissions": [ + { + "name": "ohos.permission.GET_WIFI_INFO", + "reason": "$string:wifi_info_reason", + "usedScene": { + "abilities": [], + "when": "inuse" + } + }, + { + "name": "ohos.permission.SET_WIFI_INFO", + "reason": "$string:wifi_set_reason", + "usedScene": { + "abilities": [], + "when": "inuse" + } + }, + { + "name": "ohos.permission.LOCATION", + "reason": "$string:location_reason", + "usedScene": { + "abilities": [], + "when": "inuse" + } + }, + { + "name": "ohos.permission.APPROXIMATELY_LOCATION", + "reason": "$string:location_approx_reason", + "usedScene": { + "abilities": [], + "when": "inuse" + } + } + ], +``` + +#### Add the reason for applying for the above permissions in the entry directory + +Open 'entry/src/main/resources/base/element/string. json' and add: + +```diff +... +{ + "string": [ + { + "name": "wifi_info_reason", + "value": "Need to obtain WiFi information to display the current network status of the connection" + }, + { + "name": "wifi_set_reason", + "value": "Need to configure WiFi network to connect to the specified wireless network" + }, + { + "name": "wifi_manage_reason", + "value": "Need to manage WiFi connections to provide complete network control functionality" + }, + { + "name": "wifi_mac_reason", + "value": "Need to obtain WiFi MAC address for network identification" + }, + { + "name": "location_reason", + "value": "Location permission is required to scan nearby WiFi networks (system requirement)" + }, + { + "name": "location_approx_reason", + "value": "Need approximate location permission to scan WiFi networks" + }, + { + "name": "module_desc", + "value": "React Native WiFi Manager - WiFi Network Management Module" + } + ] +} +``` + +## Attributes + +> [!TIP] The "Platform" column indicates the platforms supported by the original third-party library. + +> [!TIP] The "HarmonyOS Support" column shows "yes" if the attribute is supported on the HarmonyOS platform, "no" if not supported, and "partially" if partially supported. The usage method is consistent across platforms, and the effect aligns with that of iOS or Android. + +**wifi-reborn**:A third-party library for WiFi management in React Native, mainly used to implement various operations related to device WiFi functionality in applications. + +| Name | Description | Type | Required | Platform | HarmonyOS Support | +|-----------------|----------------------|----------|----------|-------------|-------------------| +| connectToProtectSSID | Connect to a protected SSID | function | no | Android/IOS | yes | +| suggestWifiNetwork | Recommend/prompt the specified visible WIFI network to the mobile device system | function | no | Android/IOS | yes | +| connectToProtectedWifiSSID | Connect to the protected WIFI named SSID | function | no | Android/IOS | yes | +| getCurrentWifiSSID | Return the SSID of the current WiFi network | function | no | Android/IOS | yes | +| connectToSSID | Connect to SSID | function | no | IOS | yes | +| connectToSSIDPrefix | Connect to SSID with a specific prefix | function | no | IOS | yes | +| disconnectFromSSID | Disconnect from SSID | function | no | IOS | yes | +| connectToProtectedSSIDOnce | Connect to the protected SSID once | function | no | IOS | no | +| connectToProtectedSSIDPrefix | Connect to a protected SSID with a specific prefix | function | no | IOS | yes | +| connectToProtectedSSIDPrefixOnce | Connect to a protected SSID with a specific prefix once | function | no | IOS | no | +| loadWifiList | Return to the list of nearby WIFI networks | function | no | Android | yes | +| reScanAndLoadWifiList | Rescan visible WiFi networks in the surrounding area and load and return the complete WiFi list data | function | no | Android | yes | +| isEnabled | Check if WIFI is turned on | function | no | Android | yes | +| setEnabled | Set WIFI on or off on the device | function | no | Android | yes | +| connectionStatus | The current device is connected to WIFI and has been connected, returning true | function | no | Android | yes | +| disconnect | Disconnect the current WIFI connection | function | no | Android | yes | +| getBSSID | Return the BSSID of the current WIFI connection | function | no | Android | yes | +| getCurrentSignalStrength | Return the RSSI (signal strength) of the current WIFI connection | function | no | Android | yes | +| getFrequency | Return the signal frequency of the currently connected WIFI | function | no | Android | yes | +| getIP | Return the IP address of the current WIFI connection | function | no | Android | yes | +| isRemoveWifiNetwork | Remove the specified WiFi network with saved configuration from the device | function | no | Android | yes | +| forceWifiUsage | Force the current application's network requests to go through the WIFI channel that the device is already connected to, ignoring mobile data | function | no | Android | yes | +| forceWifiUsageWithOptions | Force the current application's network requests to go through the WIFI channel that the device is already connected to, ignoring mobile data (which can be passed into the configuration object) | function | no | Android | yes | + + +## Static method + +## outstanding issues + +## other + +•The connectToProtectdSSIDOnce and connectToProtectdSSIDPriorityOnce methods cannot be implemented. These two methods are specifically designed for the iOS platform and use the NEHotspotConfiguring Manager to pass the joinOnce parameter in the iOS system to achieve one-time connection functionality. However, HarmonyOS does not support this feature. + + +## open source license + + +This project is based on [The MIT License (MIT)]( https://github.com/JuanSeBestia/react-native-wifi-reborn/blob/master/LICENSE )Please enjoy and participate freely in open source. + diff --git a/zh-cn/react-native-wifi-reborn.md b/zh-cn/react-native-wifi-reborn.md new file mode 100644 index 00000000..f494350f --- /dev/null +++ b/zh-cn/react-native-wifi-reborn.md @@ -0,0 +1,657 @@ +> 模板版本:v0.2.2 + +

+

react-native-wifi-reborn

+

+ +请到三方库的 Releases 发布地址查看配套的版本信息: + +| 三方库版本 | 发布信息 | 支持RN版本 | +| ---------- | ------------------------------------------------------------ | ---------- | +| 0.6.1 | [@react-native-ohos/react-native-wifi-reborn Releases](https://github.com/react-native-oh-library/react-native-wifi-reborn/releases) | 0.72 | +| 0.7.0 | [@react-native-ohos/react-native-wifi-reborn Releases](https://github.com/react-native-oh-library/react-native-wifi-reborn/releases) | 0.77 | + +> [!TIP] [Github 地址](https://github.com/react-native-oh-library/react-native-wifi-reborn) + +## 安装与使用 + +进入到工程目录并输入以下命令: + + + + +#### npm + +```bash +npm install @react-native-ohos/react-native-wifi-reborn +``` + +#### yarn + +```bash +yarn add @react-native-ohos/react-native-wifi-reborn +``` + + + +下面的代码展示了这个库的基本使用场景: + +> [!WARNING] 使用时 import 的库名不变。 +### wifi-reborn example +``` js +import React, { useState } from 'react'; +import { ScrollView, StyleSheet, Text, TouchableOpacity, View, TextInput, Alert } from 'react-native'; +import { Tester, TestSuite, TestCase } from '@rnoh/testerino'; +import WifiManager from 'react-native-wifi-reborn'; +import RTNPermissions, { Permission } from "react-native-permissions"; + +const permissionNormal: Permission[] = [ + 'ohos.permission.GET_WIFI_INFO', + 'ohos.permission.SET_WIFI_INFO', + 'ohos.permission.LOCATION', + 'ohos.permission.MANAGE_WIFI_CONNECTION', + 'ohos.permission.GET_WIFI_LOCAL_MAC', + 'ohos.permission.APPROXIMATELY_LOCATION', +]; + +const COLORS = { + primary: '#007AFF', + secondary: '#5856D6', + success: '#4CD964', + background: '#F2F2F7', + card: '#FFFFFF', + text: '#000000', + subText: '#8E8E93', + border: '#C7C7CC', + error: '#FF3B30', +}; + +const CustomButton = ({ title, onPress, color = COLORS.primary }: { title: string, onPress: () => void, color?: string }) => ( + + {title} + +); + +const ResultArea = ({ text }: { text: string }) => { + if (!text) return null; + return ( + + Result: + {text} + + ); +}; + +const Description = ({ text }: { text: string }) => ( + {text} +); + +export const TurboLogDemoTest = () => { + const [wifiList, setWifiList] = useState([]); + const [ssid, setSsid] = useState(''); + const [password, setPassword] = useState(''); + const [log, setLog] = useState(''); + const [results, setResults] = useState<{ [key: string]: string }>({}); + + const addLog = (msg: string) => { + console.info(msg); + setLog(prev => msg + '\n' + prev); + }; + + const updateResult = (key: string, value: string) => { + setResults(prev => ({ ...prev, [key]: value })); + addLog(`${key}: ${value}`); + }; + + const safeStringify = (val: any) => { + if (typeof val === 'string') return val; + try { + return JSON.stringify(val, null, 2); + } catch (e) { + return String(val); + } + }; + + return ( + + + + Wifi Manager Demo + + + + + + + + + + + { + try { + let requestMultiple = await RTNPermissions.requestMultiple(permissionNormal); + updateResult("Permissions", safeStringify(requestMultiple)); + } catch (e) { + updateResult("Permissions", "Error: " + safeStringify(e)); + } + }} + /> + + + + + + + + + + { + WifiManager.loadWifiList().then((list: any) => { + updateResult("loadWifiList", "Loaded " + list.length + " networks"); + setWifiList(list); + }).catch((err: any) => updateResult("loadWifiList", "Error: " + safeStringify(err))); + }} + /> + + + + {wifiList.length > 0 && ( + + Available Networks + {wifiList.map((item, index) => ( + { + setSsid(item.SSID); + addLog("Selected SSID: " + item.SSID); + }} + > + + {item.SSID || ''} + {item.level} dBm + + {item.BSSID} + {item.capabilities} + + ))} + + )} + + + + + + + { + addLog(`Connecting to ${ssid}...`); + if (password.length < 8) { + Alert.alert('密码需大于8位字符') + return + } else { + WifiManager.connectToProtectedSSID(ssid, password, false, false) + .then(() => updateResult("connectToProtectedSSID", "Connected to " + ssid)) + .catch((err: any) => updateResult("connectToProtectedSSID", "Error: " + safeStringify(err))); + } + + }} + /> + + + + + + + + + + { + WifiManager.disconnect() + .then((res: any) => updateResult("disconnect", "Disconnect: " + safeStringify(res))) + .catch((err: any) => updateResult("disconnect", "Error: " + safeStringify(err))); + }} + /> + + + + + + + + ); +}; + +const styles = StyleSheet.create({ + headerContainer: { + backgroundColor: COLORS.background, + padding: 10, + borderBottomWidth: 1, + borderBottomColor: COLORS.border, + elevation: 2, + zIndex: 100, + }, + headerTitle: { + fontSize: 20, + fontWeight: 'bold', + color: COLORS.text, + marginBottom: 10, + textAlign: 'center', + }, + inputCard: { + backgroundColor: COLORS.card, + borderRadius: 10, + padding: 10, + shadowColor: '#000', + shadowOffset: { width: 0, height: 2 }, + shadowOpacity: 0.1, + shadowRadius: 4, + elevation: 3, + }, + input: { + height: 44, + borderColor: COLORS.border, + borderWidth: 1, + borderRadius: 8, + marginBottom: 10, + paddingHorizontal: 12, + backgroundColor: '#FAFAFA', + fontSize: 16, + color: COLORS.text, + }, + testCaseContent: { + padding: 10, + }, + button: { + paddingVertical: 12, + paddingHorizontal: 20, + borderRadius: 8, + alignItems: 'center', + justifyContent: 'center', + elevation: 2, + shadowColor: '#000', + shadowOffset: { width: 0, height: 1 }, + shadowOpacity: 0.2, + shadowRadius: 2, + }, + buttonText: { + color: 'white', + fontSize: 16, + fontWeight: '600', + }, + resultContainer: { + marginTop: 10, + padding: 10, + backgroundColor: '#F8F9FA', + borderRadius: 6, + borderLeftWidth: 4, + borderLeftColor: COLORS.secondary, + }, + resultLabel: { + fontSize: 12, + color: COLORS.subText, + marginBottom: 4, + fontWeight: '600', + }, + resultText: { + fontSize: 14, + color: COLORS.text, + fontFamily: 'monospace', + }, + descriptionText: { + fontSize: 13, + color: '#666', + marginBottom: 10, + lineHeight: 18, + fontStyle: 'italic', + }, + wifiListContainer: { + padding: 10, + backgroundColor: COLORS.background, + }, + sectionTitle: { + fontSize: 18, + fontWeight: 'bold', + color: COLORS.text, + marginBottom: 10, + marginLeft: 5, + }, + wifiItem: { + padding: 15, + backgroundColor: COLORS.card, + borderRadius: 10, + marginBottom: 8, + shadowColor: '#000', + shadowOffset: { width: 0, height: 1 }, + shadowOpacity: 0.1, + shadowRadius: 2, + elevation: 2, + }, + wifiItemHeader: { + flexDirection: 'row', + justifyContent: 'space-between', + alignItems: 'center', + marginBottom: 4, + }, + wifiSSID: { + fontSize: 16, + fontWeight: 'bold', + color: COLORS.text, + }, + wifiLevel: { + fontSize: 14, + color: COLORS.success, + fontWeight: '600', + }, + wifiBSSID: { + fontSize: 12, + color: COLORS.subText, + marginBottom: 2, + }, + wifiDetails: { + fontSize: 11, + color: COLORS.subText, + fontStyle: 'italic', + }, +}); + + +``` +## Link + +此步骤为手动配置原生依赖项的指导。 + +首先需要使用 DevEco Studio 打开项目里的 HarmonyOS 工程 `harmony` + +### 1.在工程根目录的 `oh-package.json` 添加 overrides字段 + +```json +{ + ... + "overrides": { + "@rnoh/react-native-openharmony" : "./react_native_openharmony" + } + ... +} +``` + +### 2.引入原生端代码 + +目前有两种方法: + +1. 通过 har 包引入(在 IDE 完善相关功能后该方法会被遗弃,目前首选此方法); +2. 直接链接源码。 + +方法一:通过 har 包引入 (推荐) + +> [!TIP] har 包位于三方库安装路径的 `harmony` 文件夹下。 + +打开 `entry/oh-package.json5`,添加以下依赖 + +```json +"dependencies": { + "@rnoh/react-native-openharmony": "file:../react_native_openharmony", + "@react-native-ohos/react-native-wifi-reborn": "file:../../node_modules/@react-native-ohos/react-native-wifi-reborn/harmony/wifi_reborn.har" + } +``` + +点击右上角的 `sync` 按钮 + +或者在终端执行: + +```bash +cd entry +ohpm install +``` + +方法二:直接链接源码 + +> [!TIP] 如需使用直接链接源码,请参考[直接链接源码说明](/zh-cn/link-source-code.md) + + +### 4.配置 CMakeLists 和引入 turbo_log + +打开 entry/src/main/cpp/CMakeLists.txt,添加: + +```diff +include(FetchContent) +# BOOST +set(BOOST_ENABLE_CMAKE On) +FetchContent_Declare( + Boost + URL /7277/boost-1.82.0.tar.xz + OVERRIDE_FIND_PACKAGE) +project(rnapp) +cmake_minimum_required(VERSION 3.4.1) +set(CMAKE_SKIP_BUILD_RPATH TRUE) +set(RNOH_APP_DIR "${CMAKE_CURRENT_SOURCE_DIR}") +set(NODE_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../node_modules") ++ set(OH_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/../../../oh_modules") +set(RNOH_CPP_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../../oh_modules/@rnoh/react-native-openharmony/src/main/cpp") +set(RNOH_GENERATED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/generated") +set(LOG_VERBOSITY_LEVEL 1) +set(CMAKE_ASM_FLAGS "-Wno-error=unused-command-line-argument -Qunused-arguments") +set(CMAKE_CXX_FLAGS "-fstack-protector-strong -Wl,-z,relro,-z,now,-z,noexecstack -s -fPIE -pie") +set(WITH_HITRACE_SYSTRACE 1) # for other CMakeLists.txt files to use +add_compile_definitions(WITH_HITRACE_SYSTRACE) + + +add_subdirectory("${RNOH_CPP_DIR}" ./rn) + +# RNOH_BEGIN: manual_package_linking_1 +add_subdirectory("${OH_MODULES}/@react-native-ohos/react-native-gesture-handler/src/main/cpp" ./gesture-handler) ++ add_subdirectory("${OH_MODULES}/@react-native-ohos/react-native-wifi-reborn/src/main/cpp" ./wifi_reborn) +# RNOH_END: manual_package_linking_1 + +file(GLOB GENERATED_CPP_FILES "./generated/*.cpp") # this line is needed by codegen v1 +add_library(rnoh_app SHARED + ${GENERATED_CPP_FILES} + "./PackageProvider.cpp" + "${RNOH_CPP_DIR}/RNOHAppNapiBridge.cpp" +) +target_link_libraries(rnoh_app PUBLIC rnoh) + +# RNOH_BEGIN: manual_package_linking_2 +target_link_libraries(rnoh_app PUBLIC rnoh_gesture_handler) ++ target_link_libraries(rnoh_app PUBLIC rnoh_wifi_reborn) +# RNOH_END: manual_package_linking_2 + +``` + +### 4.Import the TurboLogPackage on the ArkTS side + +打开 `entry/src/main/cpp/PackageProvider.cpp`,添加: + +```diff +#include "RNOH/PackageProvider.h" +#include "generated/RNOHGeneratedPackage.h" +#include "SamplePackage.h" ++ #include "WifiRebornPackage.h" + +using namespace rnoh; + +std::vector> PackageProvider::getPackages(Package::Context ctx) { + return { + std::make_shared(ctx), + std::make_shared(ctx), ++ std::make_shared(ctx), + }; +} +``` + +### 5.运行 + +点击右上角的 `sync` 按钮 + +或者在终端执行: + +```bash +cd entry +ohpm install +``` + +然后编译、运行即可。 + +## 约束与限制 + +### 兼容性 + +本文档内容基于以下版本验证通过: +1. RNOH:0.72.90; SDK:HarmonyOS NEXT Developer DB3; IDE: DevEco Studio: 5.0.5.220; ROM:NEXT.0.0.105; +2. RNOH:0.77.18; SDK:HarmonyOS 6.0.0 Release; IDE: DevEco Studio 6.0.0.858; ROM:6.0.0.112; + +### 权限要求 + +以下权限中有`system_basic` 权限,而默认的应用权限是 `normal` ,只能使用 `normal` 等级的权限,所以可能会在安装hap包时报错**9568289**,请参考 [文档](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/bm-tool-V5#ZH-CN_TOPIC_0000001884757326__%E5%AE%89%E8%A3%85hap%E6%97%B6%E6%8F%90%E7%A4%BAcode9568289-error-install-failed-due-to-grant-request-permissions-failed) 修改应用等级为 `system_basic` + +#### 在 entry 目录下的module.json5中添加权限 + +打开 `entry/src/main/module.json5`,添加: + +```diff +... +"requestPermissions": [ + { + "name": "ohos.permission.GET_WIFI_INFO", + "reason": "$string:wifi_info_reason", + "usedScene": { + "abilities": [], + "when": "inuse" + } + }, + { + "name": "ohos.permission.SET_WIFI_INFO", + "reason": "$string:wifi_set_reason", + "usedScene": { + "abilities": [], + "when": "inuse" + } + }, + { + "name": "ohos.permission.LOCATION", + "reason": "$string:location_reason", + "usedScene": { + "abilities": [], + "when": "inuse" + } + }, + { + "name": "ohos.permission.APPROXIMATELY_LOCATION", + "reason": "$string:location_approx_reason", + "usedScene": { + "abilities": [], + "when": "inuse" + } + } + ], +``` + +#### 在 entry 目录下添加申请以上权限的原因 + +打开 `entry/src/main/resources/base/element/string.json`,添加: + +```diff +... +{ + "string": [ + { + "name": "wifi_info_reason", + "value": "需要获取WiFi信息以显示当前连接的网络状态" + }, + { + "name": "wifi_set_reason", + "value": "需要配置WiFi网络以连接到指定的无线网络" + }, + { + "name": "wifi_manage_reason", + "value": "需要管理WiFi连接以提供完整的网络控制功能" + }, + { + "name": "wifi_mac_reason", + "value": "需要获取WiFi MAC地址用于网络识别" + }, + { + "name": "location_reason", + "value": "需要位置权限以扫描附近的WiFi网络(系统要求)" + }, + { + "name": "location_approx_reason", + "value": "需要大致位置权限以扫描WiFi网络" + }, + { + "name": "module_desc", + "value": "React Native WiFi Manager - WiFi网络管理模块" + } + ] +} +``` + +## 属性 + +> [!TIP] "Platform"列表示该属性在原三方库上支持的平台。 + +> [!TIP] "HarmonyOS Support"列为 yes 表示 HarmonyOS 平台支持该属性;no 则表示不支持;partially 表示部分支持。使用方法跨平台一致,效果对标 iOS 或 Android 的效果。droid 的效果。 + +**wifi-reborn**:适用于 React Native的 WiFi 管理第三方库,主要用于在应用中实现与设备 WiFi 功能相关的各种操作。 + +| Name | Description | Type | Required | Platform | HarmonyOS Support | +|-----------------|----------------------|----------|----------|-------------|-------------------| +| connectToProtectSSID | 连接到受保护的SSID | function | no | Android/IOS | yes | +| suggestWifiNetwork | 向移动设备系统推荐/提示指定可见的 WIFI 网络 | function | no | Android/IOS | yes | +| connectToProtectedWifiSSID | 连接到名为SSID的受保护的 WIFI | function | no | Android/IOS | yes | +| getCurrentWifiSSID | 返回当前WIFI网络的SSID | function | no | Android/IOS | yes | +| connectToSSID | 连接到SSID | function | no | IOS | yes | +| connectToSSIDPrefix | 连接到特定前缀的SSID | function | no | IOS | yes | +| disconnectFromSSID | 断开与SSID的连接 | function | no | IOS | yes | +| connectToProtectedSSIDOnce | 连接到受保护的SSID一次 | function | no | IOS | no | +| connectToProtectedSSIDPrefix | 连接到受保护的特定前缀的SSID | function | no | IOS | yes | +| connectToProtectedSSIDPrefixOnce | 连接到受保护的特定前缀的SSID一次 | function | no | IOS | no | +| loadWifiList | 返回附近WIFI网络列表 | function | no | Android | yes | +| reScanAndLoadWifiList | 重新扫描周边可见 WiFi 网络,并加载返回完整的 WiFi 列表数据 | function | no | Android | yes | +| isEnabled | 检查 WIFI 是否已开启 | function | no | Android | yes | +| setEnabled | 在设备上设置 WIFI 开启或关闭 | function | no | Android | yes | +| connectionStatus | 当前设备连接 WIFI 的状态,已连接返回true | function | no | Android | yes | +| disconnect | 断开当前连接的 WIFI | function | no | Android | yes | +| getBSSID | 返回当前连接 WIFI 的BSSID | function | no | Android | yes | +| getCurrentSignalStrength | 返回当前连接 WIFI 的RSSI(信号强度) | function | no | Android | yes | +| getFrequency | 返回当前连接的 WIFI 的信号频率 | function | no | Android | yes | +| getIP | 返回当前连接 WIFI 的IP地址 | function | no | Android | yes | +| isRemoveWifiNetwork | 移除设备中已保存配置的指定 WiFi 网络 | function | no | Android | yes | +| forceWifiUsage | 强制当前应用的网络请求走设备已连接的WIFI通道,忽略移动数据 | function | no | Android | yes | +| forceWifiUsageWithOptions | 强制当前应用的网络请求走设备已连接的WIFI通道,忽略移动数据(可传入配置对象) | function | no | Android | yes | + + +## 静态方法 + +## 遗留问题 + +## 其他 + +•connectToProtectedSSIDOnce和connectToProtectedSSIDPrefixOnce方法无法实现,这两个方法是专门为ios平台设计的,在ios系统中使用了NEHotspotConfigurationManager传递joinOnce参数来实现一次连接功能,鸿蒙侧不支持此功能。 + + + +## 开源协议 + +本项目基于 [The MIT License (MIT)](https://github.com/JuanSeBestia/react-native-wifi-reborn/blob/master/LICENSE) ,请自由地享受和参与开源。 -- Gitee From 5f32ec882731bdd9a80bc33c0f7984fb0d51ec99 Mon Sep 17 00:00:00 2001 From: ZZZH Date: Tue, 6 Jan 2026 16:40:24 +0800 Subject: [PATCH 15/17] =?UTF-8?q?docs:=20[Issues:=20#IDHIT7]=E4=BF=AE?= =?UTF-8?q?=E6=94=B9react-native-wifi-reborn=E7=9A=84=E4=B8=AD=E8=8B=B1?= =?UTF-8?q?=E6=96=87=E6=8C=87=E5=AF=BC=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- en/react-native-wifi-reborn.md | 1 - zh-cn/react-native-wifi-reborn.md | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/en/react-native-wifi-reborn.md b/en/react-native-wifi-reborn.md index 28f17879..da832fc0 100644 --- a/en/react-native-wifi-reborn.md +++ b/en/react-native-wifi-reborn.md @@ -654,4 +654,3 @@ Open 'entry/src/main/resources/base/element/string. json' and add: This project is based on [The MIT License (MIT)]( https://github.com/JuanSeBestia/react-native-wifi-reborn/blob/master/LICENSE )Please enjoy and participate freely in open source. - diff --git a/zh-cn/react-native-wifi-reborn.md b/zh-cn/react-native-wifi-reborn.md index f494350f..226189aa 100644 --- a/zh-cn/react-native-wifi-reborn.md +++ b/zh-cn/react-native-wifi-reborn.md @@ -654,4 +654,4 @@ ohpm install ## 开源协议 -本项目基于 [The MIT License (MIT)](https://github.com/JuanSeBestia/react-native-wifi-reborn/blob/master/LICENSE) ,请自由地享受和参与开源。 +本项目基于 [The MIT License (MIT)](https://github.com/JuanSeBestia/react-native-wifi-reborn/blob/master/LICENSE) ,请自由地享受和参与开源。 \ No newline at end of file -- Gitee From 73e71ef003a54392988acc9681b968ac332a43bf Mon Sep 17 00:00:00 2001 From: ZZZH Date: Fri, 9 Jan 2026 17:34:55 +0800 Subject: [PATCH 16/17] =?UTF-8?q?docs:=20[Issues:=20#IDHIT7]=E4=BF=AE?= =?UTF-8?q?=E6=94=B9react-native-wifi-reborn=E7=9A=84=E4=B8=AD=E8=8B=B1?= =?UTF-8?q?=E6=96=87=E6=8C=87=E5=AF=BC=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- en/react-native-wifi-reborn.md | 4 +++- zh-cn/react-native-wifi-reborn.md | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/en/react-native-wifi-reborn.md b/en/react-native-wifi-reborn.md index da832fc0..b10aec1f 100644 --- a/en/react-native-wifi-reborn.md +++ b/en/react-native-wifi-reborn.md @@ -403,7 +403,7 @@ Currently, there are two methods: 1. Import via har package (this method will be deprecated after the IDE improves related features; currently, it is the preferred method); 2. Directly link the source code. -**Method 1: Import via har package (Recommended)** +Method 1: Import via har package (Recommended) > [!TIP] The har package is located in the `harmony` folder under the third-party library installation path. @@ -522,6 +522,7 @@ The content of this document has been verified with the following versions: 2. RNOH: 0.77.18; SDK: HarmonyOS 6.0.0 Release; IDE: DevEco Studio 6.0.0.858; ROM: 6.0.0.112; ### Permission requirements + Among the following permissions, there is a 'system_masic' permission, while the default application permission is' normal ', which can only be used at the' normal 'level. Therefore, when installing the HAP package, an error may occur * * 9568289 * *, please refer to the [document]( https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/bm-tool-V5#ZH -CN_TOPIC_0000001884757326__%E5%AE%89%E8%A3%85hap%E6%97%B6%E6%8F%90%E7%A4%BAcode9568289-error-install-failed-due-to-grant-request-permissions-failed) Change the application level to 'system_masic'` #### Add permissions to module.json5 in the entry directory @@ -648,6 +649,7 @@ Open 'entry/src/main/resources/base/element/string. json' and add: ## other •The connectToProtectdSSIDOnce and connectToProtectdSSIDPriorityOnce methods cannot be implemented. These two methods are specifically designed for the iOS platform and use the NEHotspotConfiguring Manager to pass the joinOnce parameter in the iOS system to achieve one-time connection functionality. However, HarmonyOS does not support this feature. +•setEnabled HarmonyOS only supports jumping to the Wi-Fi settings page ## open source license diff --git a/zh-cn/react-native-wifi-reborn.md b/zh-cn/react-native-wifi-reborn.md index 226189aa..2952235c 100644 --- a/zh-cn/react-native-wifi-reborn.md +++ b/zh-cn/react-native-wifi-reborn.md @@ -649,7 +649,7 @@ ohpm install ## 其他 •connectToProtectedSSIDOnce和connectToProtectedSSIDPrefixOnce方法无法实现,这两个方法是专门为ios平台设计的,在ios系统中使用了NEHotspotConfigurationManager传递joinOnce参数来实现一次连接功能,鸿蒙侧不支持此功能。 - +•setEnabled鸿蒙只支持跳转到wifi设置页 ## 开源协议 -- Gitee From 87895a64289f183be06e186713f30c89c1e13c34 Mon Sep 17 00:00:00 2001 From: zhouyong <550468167@qq.com> Date: Fri, 9 Jan 2026 20:57:28 +0800 Subject: [PATCH 17/17] =?UTF-8?q?docs:=20[Issues:=20#IDHIT7]=E4=BF=AE?= =?UTF-8?q?=E6=94=B9react-native-wifi-reborn=E7=9A=84=E4=B8=AD=E8=8B=B1?= =?UTF-8?q?=E6=96=87=E6=8C=87=E5=AF=BC=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- en/react-native-wifi-reborn.md | 4 ++-- zh-cn/react-native-wifi-reborn.md | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/en/react-native-wifi-reborn.md b/en/react-native-wifi-reborn.md index b10aec1f..673478d3 100644 --- a/en/react-native-wifi-reborn.md +++ b/en/react-native-wifi-reborn.md @@ -8,8 +8,8 @@ Please check the release information of the corresponding version at the third-p | Third-Party Library Version | Release Information | Supported RN Version | | --------------------------- | --------------------------------------------------------------- | -------------------- | -| 0.6.1 | [@react-native-ohos/react-native-wifi-reborn Releases](https://github.com/react-native-oh-library/react-native-wifi-reborn/releases) | 0.72 | -| 0.7.0 | [@react-native-ohos/react-native-wifi-reborn Releases](https://github.com/react-native-oh-library/react-native-wifi-reborn/releases) | 0.77 | +| 0.6.1 | [@react-native-ohos/react-native-wifi-reborn Releases](https://gitcode.com/OpenHarmony-RN/rntpc_react-native-wifi-reborn) | 0.72 | +| 0.7.0 | [@react-native-ohos/react-native-wifi-reborn Releases](https://gitcode.com/OpenHarmony-RN/rntpc_react-native-wifi-reborn) | 0.77 | > [!TIP] [GitHub Address](https://github.com/react-native-oh-library/react-native-wifi-reborn) diff --git a/zh-cn/react-native-wifi-reborn.md b/zh-cn/react-native-wifi-reborn.md index 2952235c..a53a6520 100644 --- a/zh-cn/react-native-wifi-reborn.md +++ b/zh-cn/react-native-wifi-reborn.md @@ -8,8 +8,8 @@ | 三方库版本 | 发布信息 | 支持RN版本 | | ---------- | ------------------------------------------------------------ | ---------- | -| 0.6.1 | [@react-native-ohos/react-native-wifi-reborn Releases](https://github.com/react-native-oh-library/react-native-wifi-reborn/releases) | 0.72 | -| 0.7.0 | [@react-native-ohos/react-native-wifi-reborn Releases](https://github.com/react-native-oh-library/react-native-wifi-reborn/releases) | 0.77 | +| 0.6.1 | [@react-native-ohos/react-native-wifi-reborn Releases](https://gitcode.com/OpenHarmony-RN/rntpc_react-native-wifi-reborn) | 0.72 | +| 0.7.0 | [@react-native-ohos/react-native-wifi-reborn Releases](https://gitcode.com/OpenHarmony-RN/rntpc_react-native-wifi-reborn) | 0.77 | > [!TIP] [Github 地址](https://github.com/react-native-oh-library/react-native-wifi-reborn) -- Gitee