我是一名 iOS 开发人员,第一次使用 React-native 涉足 Android 领域。
\n我正在创建一个使用蓝牙le的react-native应用程序,使用polidieas react-native-ble-plx库。iOS 应用程序运行良好,蓝牙扫描并检测设备。当我在 Android 上运行时,它开始扫描,并收到错误“FabricViewStateManager:在没有 StateWrapper 的情况下调用 setState”,并且找不到此错误语句的任何文档或帮助。
\n两个问题:
\n有没有人在 Anmdroid 上运行 React-Native Apps 时看到此错误:FabricViewStateManager:在没有 StateWrapper 的情况下调用 setState。
\n有人对如何隔离错误发生的位置有任何想法吗?
\n这是出现错误之前的控制台:
\nI/BluetoothAdapter: STATE_ON\nI/BluetoothAdapter: STATE_ON\nI/BluetoothAdapter: STATE_ON\nI/BluetoothAdapter: STATE_ON\nD/BluetoothLeScanner: Start Scan with callback\nD/BluetoothLeScanner: onScannerRegistered() - status=0 scannerId=13 mScannerId=0\nI/ReactNative: [GESTURE HANDLER] Initialize gesture handler for root view com.facebook.react.ReactRootView{67ef486 V.E...... ......ID 0,0-1080,2019 #1}\n**E/unknown:FabricViewStateManager: setState called without a StateWrapper**\nI/ReactNativeJS: \xe2\x94\x90 %c action %cCHANGE_STATUS %c@ 20:36:54.384\nI/ReactNativeJS: \xe2\x94\x82 '%c prev state', 'color: …我试图在连接后从蓝牙设备返回数据,因为要使用读写功能,需要一些数据。示例数据name, overflowServiceUUIDs, solicitedServiceUUIDs, mtu, rssi...和许多其他数据。因为如果我想读或写,我需要一些属性。我正在使用图书馆react-native-ble-plx。
设备连接后,我丢失了一些值。
type DeviceState = {
  connected: boolean;
  services: Service[];
  device: Device | null;
  characteristics: Record<string, Characteristic[]>;
};
const INITIAL_DEVICE_STATE = {
  connected: false,
  services: [],
  device: null,
  characteristics: {},
};
const [adapterState, setAdapterState] = useState(false);
const [bleDevices, setBleDevices] = useState<Device[]>([]);
const [isScanning, setIsScanning] = useState(false);
const [connectedDevice, setConnectedDevice] = useState<DeviceState>(
    INITIAL_DEVICE_STATE,
);
# The state isScaning is used to be if we are scanning devices.
# The connectedDevice …bluetooth bluetooth-lowenergy typescript react-native react-native-ble-plx
我在我的Pairing屏幕上注册了一个监听器,它在连接的蓝牙设备断开连接时调用一个方法
// Pairing.js
const BleManagerModule = NativeModules.BleManager;
const bleManagerEmitter = new NativeEventEmitter(BleManagerModule);
componentDidMount() {
  this.handlerDisconnected = bleManagerEmitter.addListener(
    "BleManagerDisconnectPeripheral",
    this.handlePeripheralDisconnected
  );
}
componentWillUnmount() {
  this.handlerDisconnected.remove();
}
我希望这个事件贯穿我的应用程序,如何创建全局事件侦听器而不必在每个屏幕上复制粘贴此代码?
ps 如果有帮助,我正在使用 react-native-ble-manager 和 redux+saga
我正在尝试连接到我的蓝牙设备,但是在连接并发现所有服务和特征后,我无法继续前进,因为返回的信息不足。我没有收到任何服务 UUID 或任何特征 UUID。
我需要做什么才能访问 UUID,然后才能读取特征?
我的设备调用后device.discoverAllServicesAndCharacteristics();返回:
{ _40: 0, _65: 0, _55: null, _72: null }
当我登录时device我得到:
06-23 16:36:54.758  4397  4597 I ReactNativeJS: { isConnectable: null,
06-23 16:36:54.758  4397  4597 I ReactNativeJS:   rssi: null,
06-23 16:36:54.758  4397  4597 I ReactNativeJS:   serviceData: null,
06-23 16:36:54.758  4397  4597 I ReactNativeJS:   overflowServiceUUIDs: null,
06-23 16:36:54.758  4397  4597 I ReactNativeJS:   mtu: 23,
06-23 16:36:54.758  4397  4597 I ReactNativeJS:   localName: null,
06-23 16:36:54.758  4397  4597 I ReactNativeJS:   manufacturerData: …javascript bluetooth-lowenergy react-native react-native-ble-plx