forked from codeforpublic/SQUID
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
75 lines (63 loc) · 2.56 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import 'react-native-gesture-handler'
import 'react-native-get-random-values'
import * as Sentry from '@sentry/react-native'
import { AppRegistry, Text, KeyboardAvoidingView, Platform } from 'react-native'
import App from './src/App'
import BackgroundGeolocation from './src/react-native-background-geolocation'
Text.defaultProps = Text.defaultProps || {}
Text.defaultProps.allowFontScaling = false
KeyboardAvoidingView.defaultProps.behavior =
Platform.OS == 'ios' ? 'padding' : null
if (process.env.NODE_ENV === 'production') {
Sentry.init({
dsn: 'https://[email protected]/5175128',
})
}
// Make BackgroundGeolocation API global for handy access in Javascript Debugger console
global.BackgroundGeolocation = BackgroundGeolocation
import BackgroundFetch from 'react-native-background-fetch'
AppRegistry.registerComponent('ThaiAlert', () => App)
/**
* BackgroundGeolocation Headless JS task.
* For more information, see: https://github.com/transistorsoft/react-native-background-geolocation/wiki/Android-Headless-Mode
*/
let BackgroundGeolocationHeadlessTask = async event => {
let params = event.params
console.log('[BackgroundGeolocation HeadlessTask] -', event.name, params)
switch (event.name) {
case 'heartbeat':
// Use await for async tasks
let location = await BackgroundGeolocation.getCurrentPosition({
samples: 1,
persist: false,
extras: {
triggerType: 'headlessTask',
},
})
console.log(
'[BackgroundGeolocation HeadlessTask] - getCurrentPosition:',
location,
)
break
}
}
BackgroundGeolocation.registerHeadlessTask(BackgroundGeolocationHeadlessTask)
/**
* BackgroundFetch Headless JS Task.
* For more information, see: https://github.com/transistorsoft/react-native-background-fetch#config-boolean-enableheadless-false
*/
let BackgroundFetchHeadlessTask = async event => {
console.log('[BackgroundFetch HeadlessTask] start')
// Important: await asychronous tasks when using HeadlessJS.
/* DISABLED
let location = await BackgroundGeolocation.getCurrentPosition({persist: false, samples: 1});
console.log('- current position: ', location);
// Required: Signal to native code that your task is complete.
// If you don't do this, your app could be terminated and/or assigned
// battery-blame for consuming too much time in background.
*/
console.log('[BackgroundFetch HeadlessTask] finished')
BackgroundFetch.finish()
}
// Register your BackgroundFetch HeadlessTask
BackgroundFetch.registerHeadlessTask(BackgroundFetchHeadlessTask)