-
Notifications
You must be signed in to change notification settings - Fork 153
/
index.js
executable file
·56 lines (47 loc) · 1.84 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import 'react-native-gesture-handler'; // required to fix an unhandled event due to the asynchronous router
import { AppRegistry } from 'react-native';
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 ResetMessaging from './src/ResetMessaging';
import { checkGeoSickPeople, checkBLESickPeople } from './src/services/Tracker';
import { syncLocationsDBOnLocationEvent } from './src/services/SampleService';
import { onError } from './src/services/ErrorService';
import { initBLETracing } from './src/services/BLEService';
import { initConfig } from './src/config/config';
import { IS_IOS } from './src/constants/Constants';
BackgroundGeolocation.onLocation(
async () => {
await syncLocationsDBOnLocationEvent();
if (IS_IOS) {
await initBLETracing();
}
}, (error) => {
onError({ error });
}
);
const BackgroundFetchHeadlessTask = async (event) => {
try {
const { taskId } = event;
console.log('[BackgroundFetch HeadlessTask] start: ', taskId);
if (IS_IOS) {
initBLETracing();
}
await initConfig();
await syncLocationsDBOnLocationEvent();
await checkBLESickPeople();
await checkGeoSickPeople();
BackgroundFetch.finish(taskId);
} catch (error) {
onError({ error });
}
};
const BackgroundGeolocationHeadlessTask = async (event) => {
console.log('[BackgroundGeolocation HeadlessTask] -', event.name);
await syncLocationsDBOnLocationEvent();
};
AppRegistry.registerComponent(appName, () => App);
AppRegistry.registerHeadlessTask('RNFirebaseBackgroundMessage', () => ResetMessaging);
BackgroundFetch.registerHeadlessTask(BackgroundFetchHeadlessTask);
BackgroundGeolocation.registerHeadlessTask(BackgroundGeolocationHeadlessTask);