AirLink 配网
AirLink 是广播配网,不能保证只配置某一台设备。productKeys 指定用于云端确认的产品列表,timeout 单位为秒。当前仅原生模块导出该接口,必须传结果回调,不能直接 await 原生方法的返回值。
import { NativeEventEmitter, NativeModules } from 'react-native';
import type { Types } from 'react-native-gizwits-sdk-v5';
const nativeDeviceManager = NativeModules.RNGizDeviceManagerModule;
const emitter = new NativeEventEmitter(nativeDeviceManager);
const subscription = emitter.addListener('GizProvideWiFiCredentialsEvent', event => {
if (event.data === 'WIFI_CONFIG_SUCCESS' || event.data === 1013) {
console.log('Provisioning succeeded');
}
});
try {
const result = await new Promise<Types.GizResult<unknown, unknown>>(resolve => {
nativeDeviceManager.provideWiFiCredentialsWithAirLink(
{ ssid, password, timeout: 60, productKeys: ['PK1'] },
(error: Types.GizResult<unknown, unknown> | null, data: Types.GizResult<unknown, unknown>) => {
resolve(error ?? data);
},
);
});
if (!result.success) console.log(result.error, result.message);
} finally {
subscription.remove();
}停止广播配网(该接口只接收回调,不接收 options):
import type { Types } from 'react-native-gizwits-sdk-v5';
nativeDeviceManager.stopProvideWiFiCredentialsWithAirLink((
error: Types.GizResult<unknown, unknown> | null,
data: Types.GizResult<unknown, unknown>,
) => {
console.log(error ?? data);
});