Quantcast
Channel: Active questions tagged react-native+ios - Stack Overflow
Viewing all articles
Browse latest Browse all 16750

Cannot unregister or stop a Geofence task

$
0
0

A Geofence background task I've defined and registered gets triggered multiple times instead of once. This behavior generates multiple Enter and Leave events with different region ids(expo region type.

import React, {Component} from 'react';
import {View, Text} from 'react-native';

import * as TaskManager from 'expo-task-manager';
import * as Location from 'expo-location';
import * as Permissions from 'expo-permissions';

const SAMPLE_TASK = 'sample-task';
//
// Location.stopGeofencingAsync(SAMPLE_TASK);
// TaskManager.unregisterTaskAsync(SAMPLE_TASK);

const askPermission = async () => {
  let status = await Permissions.askAsync(Permissions.LOCATION);
  console.log(status);
  if (status.status !== 'granted') {
    console.log('Permission to access location was denied');
  }
};

const monitorGeoFenceTask = async (payload) => {
  console.log(payload);
};

const registerGeofenceTask = async () => {
  const registered = await TaskManager.isTaskRegisteredAsync(SAMPLE_TASK);
  console.log('Is registered', registered);

  if (registered) {
    const stopGeo =  await Location.stopGeofencingAsync(SAMPLE_TASK);
    Location.startGeofencingAsync(SAMPLE_TASK, [
      {
        latitude: 32.296048,
        longitude: -90.178607,
        radius: 50,
      }]);
  }
  else{
    Location.startGeofencingAsync(SAMPLE_TASK, [
      {
        latitude: 32.296048,
        longitude: -90.178607,
        radius: 50,
      }]);
  }
};


askPermission();
registerGeofenceTask();

TaskManager.defineTask(SAMPLE_TASK, monitorGeoFenceTask);

export default class App extends Component {
  render() {
    return (
        <View>
          <Text>Open up App.js to start working on your app!</Text>
        </View>
    );
  }
}

I've tried using Location.stopGeofencingAsync(SAMPLE_TASK) and TaskManager.unregisterTaskAsync(SAMPLE_TASK) to delete old tasks but it doesn't seem work.

Output from idevicesyslog | grep sample-task

Dec 22 22:06:52 iPhone IoPrealphar[2920] <Notice>: EXTaskService: Executing task 'sample-task' for app '@app'.
Dec 22 22:06:54 iPhone IoPrealphar[2920] <Notice>: EXTaskService: Executing task 'sample-task' for app '@app'.

Viewing all articles
Browse latest Browse all 16750

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>