-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
57 lines (46 loc) · 1.42 KB
/
App.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
import React, { useEffect } from 'react';
import { StatusBar, BackHandler, Alert, AsyncStorage } from 'react-native'
import * as Location from 'expo-location';
import 'react-native-gesture-handler';
import Index from './src/index';
export default function App() {
useEffect(() => {
const AsyncAlert = async (message) => new Promise((resolve) => {
Alert.alert(
'Alerta',
message,
[
{
text: 'OK',
onPress: () => {
resolve('YES');
},
},
],
{ cancelable: false },
);
});
async function alertIfRemoteNotificationsDisabledAsync() {
const { status } = await Location.requestForegroundPermissionsAsync();
if (status !== 'granted') {
await AsyncAlert('Olá! Para o funcionamento correto do aplicativo, é necessário ativar a localização.');
BackHandler.exitApp();
}
else {
let location = await Location.getCurrentPositionAsync({ enableHighAccuracy: true });
location = await Location.reverseGeocodeAsync({
latitude: location.coords.latitude,
longitude: location.coords.longitude,
});
await AsyncStorage.setItem('location', JSON.stringify(location[0]));
}
}
alertIfRemoteNotificationsDisabledAsync()
}, [])
return (
<>
<StatusBar barStyle="light-content" />
<Index></Index>
</>
);
}