我想使用 RN + expo 创建我自己的类似 Endomono/Runtastic 的应用程序(这个应用程序只适合我,我有性能/电池寿命相当不错的安卓手机(红米手机注 7),所以我不用担心性能问题太多了)。我想为此使用多合一库,或者只是使用允许我在后台每 X 秒执行一些代码的库(并在那里使用 getAsyncLocation)。我的观点只是每隔 X 秒将纬度/经度数据发送到我的后端 HTTP django-rest-framework 服务器。
我花了一整天的时间试图找出任何方法来做到这一点,我尝试了几个这样的库:react-native-background-geolocation、react-native-background-timer、react-native-background-job等等。我也跟着一步一步安装目录指导,我一直得到这样的错误:null is not an object (evaluating 'RNBackgroundTimer.setTimeout')。
我也试过这个:我修复了这段代码中的一些错误(与导入相关),它似乎有效,但是当我使用假 GPS 更改我的 GPS 位置时,控制台中只出现一个 didFocus 函数。这是代码:
import React from 'react';
import { EventEmitter } from 'fbemitter';
import { NavigationEvents } from 'react-navigation';
import { AppState, AsyncStorage, Platform, StyleSheet, Text, View, Button } from 'react-native';
import MapView from 'react-native-maps';
import * as Permissions from 'expo-permissions';
import * …Run Code Online (Sandbox Code Playgroud)