react-native - React Native - 如何从 Expo 中的 TaskManager 访问承诺值?
问题描述
当我进入地理围栏时,我正在测试后台定位任务,以与 Expo 的任务管理器进行本机反应。我已经掌握了基础知识,但我现在正在尝试访问从其中一项任务返回的承诺中的值,以便我可以显示您是否已进入或退出地理围栏。谁能帮我弄清楚如何正确访问我想要的值?
以下是与地理围栏相关的任务部分。我返回作为承诺的价值区域。我还没有弄清楚如何直接从任务管理器发送:
// 3 Define geofencing task
TaskManager.defineTask(TASK_CHECK_GEOFENCE, ({ data: { eventType, region }, error }) => {
if (error) {
// check `error.message` for more details.
return;
}
if (eventType === Location.GeofencingEventType.Enter) {
console.log("You've entered region:", region);
//this.props.setEnterRegion({ inRegion: region })
const final = region
return final
} else if (eventType === Location.GeofencingEventType.Exit) {
console.log("You've left region:", region);
const final = region
return final
}
});
然后在 App.js 中,我在 componentDidMount 中调用该应用程序:
componentDidMount() {
this.getLocationsPermissions();
this.startBackgroundUpdate();
this.startGeofence();
}
//define and start geofence
startGeofence = async () => {
console.log('starting geofencing test ...')
let x = Location.startGeofencingAsync('TASK_CHECK_GEOFENCE',
[
{
identifier: 'court',
latitude: this.state.myLocation.latitude,
longitude: this.state.myLocation.longitude,
radius: 20,
notifyOnEnter: true,
notifyOnExit: true,
}
]
)
this.sendTask(x)
};
当我尝试访问该值时,我可以看到承诺,但我不确定我哪里出错了。我更愿意直接从任务管理器发送到商店,但我遇到了麻烦:
//send to store from task
sendTask = (x) => {
console.log('entered region...', x)
this.props.setEnterRegion(x)
entered region... Promise {
"_40": 0,
"_55": null,
"_65": 0,
"_72": null,
}
解决方案
推荐阅读
- python - 如何在python中输入超过数字中的特定值
- javascript - 如何使用 deck.gl MVtLayer 显示自托管图块?
- javascript - React - 如何从多个输入中获取值并将它们发送到我的输入?
- python - 如何计算测试数据的混淆矩阵?
- javascript - 如何将一组对象(不同长度)转换为一个具有与原始数组中元素不同属性的对象?
- python - 如何将实时数据拆分为条形图
- json - 如何将ruby文件转换为json?
- javascript - ReactJS 转换成类
- python - 使用 Keras 给单词组合打分
- java - 类和映射,hashMap 不可变 cl?