Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save GillesVercammen/77a4dd2c5e9ffffb497b5128891e137a to your computer and use it in GitHub Desktop.
Save GillesVercammen/77a4dd2c5e9ffffb497b5128891e137a to your computer and use it in GitHub Desktop.
start service and check status
_handleAppStateChange = appState => {
const { status, manualStop } = this.state
if (appState === 'active') {
this._updatePermissions('location', 'handle')
if (status === 'authorized' && !manualStop) {
console.log('[NOTE] app is in handleAppstate and authorized, starting tracking!!!')
BackgroundGeolocation.configure({
locationProvider: BackgroundGeolocation.RAW_PROVIDER,
interval: 20000,
fastestInterval: 5000,
activitiesInterval: 10000
})
console.log('HANDLE STATE AND STARTING')
BackgroundGeolocation.stop()
BackgroundGeolocation.start() // THE SERVICE GETS STARTED HERE FOR FIRST TIME
}
}
// THIS IS RUNNING BEFORE THE SERVICE ACTUALLY STARTED
BackgroundGeolocation.checkStatus(({ isRunning }) => {
console.log('[NOTE] CHECKING THE TRACKING STATUS!!!')
if (isRunning) {
console.log('[NOTE] TRACKING IS RUNNING')
this.setState({ isTrackingRunning: true })
} else {
console.log('[NOTE] TRACKING IS NOT RUNNING')
this.setState({ isTrackingRunning: false })
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment