Advertisement
Guest User

Untitled

a guest
Jan 20th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, { Component } from 'react';
  2. import BackgroundGeolocation from 'react-native-mauron85-background-geolocation';
  3. import { Alert, View, Text } from 'react-native';
  4. import {
  5.   Container,
  6.   Header,
  7.   Title,
  8.   Content,
  9.   Footer,
  10.   FooterTab,
  11.   Button,
  12.   Icon
  13. } from 'native-base';
  14.  
  15. import AllLocationsScene from './src/components/AllLocationsScene';
  16.  
  17. export default class App extends Component {
  18.  
  19.   componentDidMount() {
  20.     BackgroundGeolocation.configure({
  21.       desiredAccuracy: 100,
  22.       stationaryRadius: 0,
  23.       distanceFilter: 0,
  24.       notificationTitle: 'Background tracking',
  25.       notificationText: 'enabled',
  26.       debug: true,
  27.       startOnBoot: false,
  28.       stopOnTerminate: true,
  29.       locationProvider: BackgroundGeolocation.ACTIVITY_PROVIDER,
  30.       interval: 1000,
  31.       fastestInterval: 5000,
  32.       activitiesInterval: 1000,
  33.       stopOnStillActivity: false,
  34.       url: 'http://192.168.1.10/api/v1/entregadores/location',
  35.       httpHeaders: {
  36.         'X-FOO': 'bar'
  37.       }
  38.     });
  39.  
  40.     BackgroundGeolocation.on('location', (location) => {
  41.       // handle your locations here
  42.       // to perform long running operation on iOS
  43.       // you need to create background task
  44.       BackgroundGeolocation.startTask(taskKey => {
  45.         // execute long running task
  46.         // eg. ajax post location
  47.         // IMPORTANT: task has to be ended by endTask
  48.         BackgroundGeolocation.endTask(taskKey);
  49.       });
  50.     });
  51.  
  52.     BackgroundGeolocation.on('stationary', (stationaryLocation) => {
  53.       // handle stationary locations here
  54.       Actions.sendLocation(stationaryLocation);
  55.     });
  56.  
  57.  
  58.     BackgroundGeolocation.on('authorization', (status) => {
  59.       console.log('[INFO] BackgroundGeolocation authorization status: ' + status);
  60.       if (status !== BackgroundGeolocation.AUTHORIZED) {
  61.         Alert.alert('Localização esta desabilitado', 'Abrir configurações de lozalização?', [
  62.           { text: 'Sim', onPress: () => BackgroundGeolocation.showLocationSettings() },
  63.           { text: 'Não', onPress: () => console.log('No Pressed'), style: 'cancel' }
  64.         ]);
  65.       }
  66.     });
  67.  
  68.     BackgroundGeolocation.on('background', () => {
  69.       console.log('[INFO] App is in background');
  70.     });
  71.  
  72.     BackgroundGeolocation.on('foreground', () => {
  73.       console.log('[INFO] App is in foreground');
  74.     });
  75.  
  76.     // you can also just start without checking for status
  77.     BackgroundGeolocation.start();
  78.     console.log('Em teoria começou');
  79.   }
  80.  
  81.   render() {
  82.  
  83.     return (
  84.      
  85.         <View>
  86.           <AllLocationsScene />
  87.         </View>
  88.      
  89.     );
  90.   }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement