0

我遇到了react-native-sensor问题,它在 1 分钟后无法在后台工作。我的手机是Mi 10 Lite Android 10。这是我的代码。

useEffect(() => {
    setUpdateIntervalForType(SensorTypes.accelerometer, 200);
   
    const sensorSubs = accelerometer
        .pipe(map(({ x, y, z }) => Math.sqrt((x * x) + (y * y) + (z * z)) /* - SensorManager.GRAVITY_EARTH */),
          filter(acceleration => acceleration >= minAcceleration ),
          filter(speed => speed >= minSpeed ? speedShake.current = 100 : speedShake.current = 600 ))
        .subscribe(acceleration => {
          console.log(acceleration)
        })
    
    return () => { sensorSubs.unsubscribe() }
  }, [])

为什么不在后台工作?有人能帮我吗。谢谢!

4

0 回答 0