Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"react-native-code-push": "^6.2.0",
"react-native-config": "^1.0.0",
"react-native-contact-tracer": "git://github.com/Morchana/contact-tracer.git",
"react-native-device-info": "^5.5.3",
"react-native-device-info": "^8.0.0",
"react-native-easy-grid": "^0.2.0",
"react-native-elements": "^1.2.7",
"react-native-event-listeners": "^1.0.7",
Expand Down
18 changes: 18 additions & 0 deletions src/services/background-tracking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { getAnonymousHeaders } from '../api'
import { Platform } from 'react-native'
import { API_URL } from '../config'
import I18n from '../../i18n/i18n'
import DeviceInfo from 'react-native-device-info'
class BackgroundTracking {
setup(startImmediately?: boolean) {
if (startImmediately) {
Expand Down Expand Up @@ -57,6 +58,9 @@ class BackgroundTracking {
}

start() {
if (!this.canUseGeoLocation) {
return Promise.resolve()
}
return this.registerGeoLocation().then((state) => {
if (!state.enabled) {
BackgroundGeolocation.start().catch(console.log)
Expand All @@ -65,22 +69,36 @@ class BackgroundTracking {
}

stop() {
if (!this.canUseGeoLocation) {
return Promise.resolve()
}
BackgroundGeolocation.removeAllListeners()
return BackgroundGeolocation.stop()
}

destroyLocations() {
if (!this.canUseGeoLocation) {
return Promise.resolve()
}
return BackgroundGeolocation.destroyLocations()
}

getLocation(extras: any = {}) {
if (!this.canUseGeoLocation) {
return Promise.resolve({ ...extras })
}
return this.registerGeoLocation().then(() => {
return BackgroundGeolocation.getCurrentPosition({
samples: 1,
...extras,
})
})
}

get canUseGeoLocation() {
const hasGMS = DeviceInfo.hasGmsSync()
return Platform.OS === 'ios' || hasGMS
}
}

export const backgroundTracking = new BackgroundTracking()
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7983,10 +7983,10 @@ react-native-datepicker@^1.4.4:
dependencies:
moment "^2.22.0"

react-native-device-info@^5.5.3:
version "5.5.4"
resolved "https://registry.yarnpkg.com/react-native-device-info/-/react-native-device-info-5.5.4.tgz#470770db4e8a35c55b8269473d81790102074057"
integrity sha512-koR7ZvL4V+34GwhjQxb3PNZLElpEzAvDG5AE4KIc70ufKMEHJL9VCpRXBMelihlA0u9PlYzuMgBs7tovNRAzFw==
react-native-device-info@^8.0.0:
version "8.0.0"
resolved "https://registry.yarnpkg.com/react-native-device-info/-/react-native-device-info-8.0.0.tgz#a481ea6d445483329aefcb91c753987931ad4756"
integrity sha512-7/DOEhg8GtyW1hpVtWf8F6RvGLaFaOGmex+IkmiBWQC2uW4NFDcfXm+lMMZnduFavTyUTX7AF6lAM3y286cEfA==

react-native-drawer-menu@^0.2.3:
version "0.2.5"
Expand Down