Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import React, { Component } from 'react';
- import BackgroundGeolocation from 'react-native-mauron85-background-geolocation';
- import { Alert, View, Text } from 'react-native';
- import {
- Container,
- Header,
- Title,
- Content,
- Footer,
- FooterTab,
- Button,
- Icon
- } from 'native-base';
- import AllLocationsScene from './src/components/AllLocationsScene';
- export default class App extends Component {
- componentDidMount() {
- BackgroundGeolocation.configure({
- desiredAccuracy: 100,
- stationaryRadius: 0,
- distanceFilter: 0,
- notificationTitle: 'Background tracking',
- notificationText: 'enabled',
- debug: true,
- startOnBoot: false,
- stopOnTerminate: true,
- locationProvider: BackgroundGeolocation.ACTIVITY_PROVIDER,
- interval: 1000,
- fastestInterval: 5000,
- activitiesInterval: 1000,
- stopOnStillActivity: false,
- url: 'http://192.168.1.10/api/v1/entregadores/location',
- httpHeaders: {
- 'X-FOO': 'bar'
- }
- });
- BackgroundGeolocation.on('location', (location) => {
- // handle your locations here
- // to perform long running operation on iOS
- // you need to create background task
- BackgroundGeolocation.startTask(taskKey => {
- // execute long running task
- // eg. ajax post location
- // IMPORTANT: task has to be ended by endTask
- BackgroundGeolocation.endTask(taskKey);
- });
- });
- BackgroundGeolocation.on('stationary', (stationaryLocation) => {
- // handle stationary locations here
- Actions.sendLocation(stationaryLocation);
- });
- BackgroundGeolocation.on('authorization', (status) => {
- console.log('[INFO] BackgroundGeolocation authorization status: ' + status);
- if (status !== BackgroundGeolocation.AUTHORIZED) {
- Alert.alert('Localização esta desabilitado', 'Abrir configurações de lozalização?', [
- { text: 'Sim', onPress: () => BackgroundGeolocation.showLocationSettings() },
- { text: 'Não', onPress: () => console.log('No Pressed'), style: 'cancel' }
- ]);
- }
- });
- BackgroundGeolocation.on('background', () => {
- console.log('[INFO] App is in background');
- });
- BackgroundGeolocation.on('foreground', () => {
- console.log('[INFO] App is in foreground');
- });
- // you can also just start without checking for status
- BackgroundGeolocation.start();
- console.log('Em teoria começou');
- }
- render() {
- return (
- <View>
- <AllLocationsScene />
- </View>
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement