-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathApp.js
88 lines (73 loc) · 2.04 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import React from 'react'
import { StyleSheet, View, Text, PermissionsAndroid } from 'react-native'
import Eddystone from "@lg2/react-native-eddystone"
export default class App extends React.Component {
constructor(props) {
super(props)
this.state = {
data: "Sem BLE beacon",
beacon: ""
}
this.onUID = this.onUID.bind(this)
}
async componentDidMount() {
await this.getAccessFineLocation()
Eddystone.addListener("onUIDFrame", this.onUID)
Eddystone.startScanning()
this.beaconMonitoring()
}
onUID(beacon) {
console.log("UIDFrame:", beacon)
this.setState({ beacon: beacon.id })
}
beaconMonitoring(refreshTime = 500) {
setInterval(() => {
if (this.state.beacon) {
this.setState({ data: this.state.beacon })
this.setState({ beacon: "" })
} else {
this.setState({ data: "Sem BLE beacon" })
}
}, refreshTime)
}
async getAccessFineLocation() {
/*requisita acesso à localização do usuário
Android: também é necessário configurar o android/app/src/main/AndroidManifext.xml
https://reactnative.dev/docs/permissionsandroid
*/
try {
const granted = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
{
title: "ACCESS_FINE_LOCATION",
message: "ACCESS_FINE_LOCATION",
buttonNeutral: "Ask Me Later",
buttonNegative: "Cancel",
buttonPositive: "OK"
}
);
if (granted === PermissionsAndroid.RESULTS.GRANTED) {
console.log("OK -> ACCESS_FINE_LOCATION");
} else {
console.log("NOT OK -> ACCESS_FINE_LOCATION");
}
} catch (err) {
console.warn(err);
}
}
render() {
return (
<View style={styles.container}>
<Text style={{ fontSize: 20, color: "#ff6a00" }}>{this.state.data}</Text>
</View>
)
}
}
const styles = StyleSheet.create({
container: {
flexDirection: 'row',
flex: 1,
justifyContent: 'center',
alignItems: 'center'
}
});