react-native - Pedometer.watchStepCount 没有发出任何信号
问题描述
我正在使用 react-native / expo 并尝试访问计步器。我的代码在 iOS Expo Go 应用程序上一切正常,但在 Android Expo(诺基亚 7.2 / Android 10)上我没有收到来自Pedometer.watchStepCount
.
这是我在进入“WalkScreen”之前正在做的事情:
const alertIfMotionDisabledAsync = async () => {
const { status } = await Pedometer.requestPermissionsAsync();
if (status !== 'granted') {
Toast.show({
text: "Sorry! Your sensors aren't activated. Please check that you've allowed them for the Synchronisator.",
buttonText: "Okay",
position: "top",
type: "danger",
});
} else {
navigation.navigate("Walk");
}
}
这是我访问计步器的方式:
const subscribeToPedometer = () => {
let thisWalking = false;
let currentStepCountBefore = 0;
const subscription = Pedometer.watchStepCount(result => {
if (currentStepCountBefore === result.steps && thisWalking) {
setWalking(false);
thisWalking = false;
} else if (!thisWalking) {
setWalking(true);
thisWalking = true;
}
currentStepCountBefore = result.steps;
setCurrentStepCount(result.steps);
console.log("Pedometer.watchStepCount result.steps", result.steps);
});
setPedometerSubscription(subscription);
Pedometer.isAvailableAsync().then(
result => {
console.log("isAvailableAsync", result);
setIsPedometerAvailable(result);
},
error => {
console.log('Could not get isPedometerAvailable: ' + error);
setIsPedometerAvailable(false);
}
);
};
我没有任何问题地进入步行屏幕,因此授予状态。在Pedometer.isAvailableAsync()
方法中,我得到了真实的,所以它似乎是可用的。但是我的 console.log 中没有任何数据console.log("Pedometer.watchStepCount result.steps", result.steps);
。
解决方案
推荐阅读
- python - 我已经为 yolo(CPU 版本)安装了暗网,但它没有使用 opencv
- c++ - C 和 C++ 中布尔值的 sizeof 运算符的输出差异
- java - 基于 Java 的 Azure 函数 - 异常:ClassCastException:无法强制转换类 jdk.internal.loader.ClassLoaders$AppClassLoader
- spring-boot - 不从表中删除记录
- flutter - 捕获流中引发的错误侦听
- angular - 动作守卫/中间件 - 如何检查条件?
- c++ - 不再支持命名返回值错误
- git - 使用 IntelliJ IDE 强制推送 Git
- c# - 从 WPF 中的另一个线程更新文本框
- arrays - bash 中的匿名管道列表