forked from MohGovIL/hamagen-react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·40 lines (34 loc) · 1.36 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import 'react-native-gesture-handler'; // required to fix an unhandled event due to the asynchronous router
import { AppRegistry } from 'react-native';
import moment from 'moment';
import BackgroundFetch from 'react-native-background-fetch';
import BackgroundGeolocation from 'react-native-background-geolocation';
import App from './src/App';
import { name as appName } from './app.json';
import { checkSickPeople } from './src/services/Tracker';
import { insertDB } from './src/services/SampleService';
import { onError } from './src/services/ErrorService';
BackgroundGeolocation.onLocation(
async (location) => {
location.timestamp = moment(location.timestamp).valueOf();
await insertDB(location);
}, (error) => {
onError({ error });
}
);
const BackgroundFetchHeadlessTask = async (event) => {
try {
const { taskId } = event;
console.log('[BackgroundFetch HeadlessTask] start: ', taskId);
await checkSickPeople();
BackgroundFetch.finish(taskId);
} catch (error) {
onError({ error });
}
};
const BackgroundGeolocationHeadlessTask = async (event, params) => {
console.log('[BackgroundGeolocation HeadlessTask] -', event.name, params);
};
AppRegistry.registerComponent(appName, () => App);
BackgroundFetch.registerHeadlessTask(BackgroundFetchHeadlessTask);
BackgroundGeolocation.registerHeadlessTask(BackgroundGeolocationHeadlessTask);