Javascript Expo Location.startLocationUpdatesAsync后台服务不';无法在真实设备上工作(包括ios和android)

Javascript Expo Location.startLocationUpdatesAsync后台服务不';无法在真实设备上工作(包括ios和android),javascript,reactjs,react-native,expo,Javascript,Reactjs,React Native,Expo,我使用expo framework开发react本机移动应用程序,该应用程序的要求之一是在用户位置超出边界时,使用axio API请求将用户位置(lat、lng)发送到我们的后端服务。这意味着我们需要持续监视当前用户的位置,并计算从用户的初始位置到用户的当前位置的距离。因此,我实现了Location.startLocationUpdatesAsync来接收位置更新,当应用程序在后台时也可以接收位置更新。然而,Expo Location.startLocationUpdatesAsync方法只能在

我使用expo framework开发react本机移动应用程序,该应用程序的要求之一是在用户位置超出边界时,使用axio API请求将用户位置(lat、lng)发送到我们的后端服务。这意味着我们需要持续监视当前用户的位置,并计算从用户的初始位置到用户的当前位置的距离。因此,我实现了Location.startLocationUpdatesAsync来接收位置更新,当应用程序在后台时也可以接收位置更新。然而,Expo Location.startLocationUpdatesAsync方法只能在模拟器上工作,当我们使用真实设备对其进行测试时,它不起作用。我想知道我的项目中是否缺少任何配置,因此无法使用真实设备(ios和android)处理此方法

}

componentDidMount = async () => {
    const { status } = await Location.requestPermissionsAsync();

    if (status === 'granted') {
        await Location.startLocationUpdatesAsync(LOCATION_TASK_NAME, {
            accuracy: Location.Accuracy.Balanced,
            showsBackgroundLocationIndicator: true
            // deferredUpdatesInterval : 10000

        });
    }
};......................
const calculateBoundary = (lat1, lon1, lat2, lon2, unit) => {
if ((lat1 == lat2) && (lon1 == lon2)) {
    return 0;
}
else {
    var radlat1 = Math.PI * lat1 / 180;
    var radlat2 = Math.PI * lat2 / 180;
    var theta = lon1 - lon2;
    var radtheta = Math.PI * theta / 180;
    var dist = Math.sin(radlat1) * Math.sin(radlat2) + Math.cos(radlat1) * Math.cos(radlat2) * Math.cos(radtheta);
    if (dist > 1) {
        dist = 1;
    }
    dist = Math.acos(dist);
    dist = dist * 180 / Math.PI;
    dist = dist * 60 * 1.1515;
    if (unit == "K") { dist = dist * 1.609344 }
    if (unit == "N") { dist = dist * 0.8684 }
    return dist;
}
TaskManager.defineTask(LOCATION_TASK_NAME, async({ data, error }) => {
if (error) {
    // Error occurred - check `error.message` for more details.
    return;
}
if (data) {
    const { locations } = data;
    const timeStamp = (new Date().getTime()/1000).toString().split(".")[0];

    try {
        const value = await AsyncStorage.getItem('user');
        if (value !== null) {
            //console.log(value);
            // We have data!!
            const email = '';
            const phone = JSON.parse(value).phone_number;
            const name = JSON.parse(value).given_name

            const urlList = "https://coxj3a2v77.execute-api.ap-southeast-2.amazonaws.com/production/profile/list";
            const urlSns ="https://coxj3a2v77.execute-api.ap-southeast-2.amazonaws.com/production/sns";
            const urlEvent ="https://coxj3a2v77.execute-api.ap-southeast-2.amazonaws.com/production/event";

            axios.get(urlList)
                .then(function (response) {
                    // handle success
                    //console.log("!!!" + JSON.stringify(response.data));
                    const initLocation = { lat: response.data.lat, lng: response.data.lng };
                    const initLat = initLocation.lat;
                    const initLng = initLocation.lng;
                    //let count=0;
                    const K = calculateBoundary(initLat, initLng, locations[0].coords.latitude, locations[0].coords.longitude, "K");
                    if(K>0.25){
                        console.log("Warning!!"+K)
                        const SnsPayload ={
                            name: name, 
                            email: email, 
                            phone_number: phone, 
                            lat: locations[0].coords.latitude, 
                            lng: locations[0].coords.longitude
                        }
                        const EventPayload={
                            email: email, 
                            lat: locations[0].coords.latitude, 
                            lng: locations[0].coords.longitude, 
                            time_stamp: timeStamp
                        }
                        console.log(SnsPayload);
                        axios.post(urlSns, SnsPayload)
                            .then(function (response) {
                                console.log("SNS:"+response);
                                //self.setState({ dialogVisible: true })
                            })
                            .catch(function (error) {
                                console.log(error);
                            });