React Native-如何从Expo中的TaskManager访问Promise值?

问题描述

我正在测试背景定位任务,以使用Expo的taskmanager进行本机反应,以测试进入地理围栏时的情况。我已经掌握了基础知识,但是现在我正尝试访问其中一项任务返回的Promise中的值,这样我就可以显示您是否已进入或退出地理围栏。谁能帮助我弄清楚如何正确访问所需的值?

以下是与地理围栏相关的任务部分。我返回了一个有希望的价值区域。我还无法弄清楚如何直接从任务管理器发送:

   // 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)
  
};

当我尝试访问该值时,我可以看到承诺,但不确定要去哪里。我希望直接从taskmanager发送到商店,但是我遇到了麻烦:

//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,}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...