You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would like to get an alert(); message, when the beacon i am scanning for is found.
I start scanning for that beacon with a tap on a TouchableHightlight.
Actual behavior
But i am getting this alert every time when I press the Scan Button although the beacon is powered off. Other apps tell me the beacon is not visible/reachable.
Can anyone help me to solve this problem and that I only get this alert, when the beacon is on and found? And that I get an 'Beacon not found'?
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View,
TouchableHighlight,
DeviceEventEmitter,
TextInput,
} from 'react-native';
Beacons.requestAlwaysAuthorization();
/*
Code
*/
class beaconScanner extends Component {
_scanningForBeacon ()
{
//alert('Start');
//this.state.logInputText = "Starte Scanning";
// Request for authorization while the app is open
Beacons.startMonitoringForRegion(beaconRegion);
Beacons.startRangingBeaconsInRegion(beaconRegion);
//Beacons.startUpdatingLocation();
// Listen for beacon changes
var subscription = DeviceEventEmitter.addListener(
'beaconsDidRange',
(data) => {
if (data)
{
alert('FOUND: '+data.region.uuid);
Beacons.stopMonitoringForRegion(data.region);
Beacons.stopRangingBeaconsInRegion(data.region);
}
else {
alert('No beacon found');
}
// data.region - The current region
// data.region.identifier
// data.region.uuid
// data.beacons - Array of all beacons inside a region
// in the following structure:
// .uuid
// .major - The major version of a beacon
// .minor - The minor version of a beacon
// .rssi - Signal strength: RSSI value (between -100 and 0)
// .proximity - Proximity value, can either be "unknown", "far", "near" or "immediate"
// .accuracy - The accuracy of a beacon
}
);
I believe the dataobject in the beaconsDidRange event always will be present as an object. However to check if you have nearby beacons you should look for the beacons array property. Eg:
Version
0.6.0
Expected behavior
I would like to get an alert(); message, when the beacon i am scanning for is found.
I start scanning for that beacon with a tap on a TouchableHightlight.
Actual behavior
But i am getting this alert every time when I press the Scan Button although the beacon is powered off. Other apps tell me the beacon is not visible/reachable.
Can anyone help me to solve this problem and that I only get this alert, when the beacon is on and found? And that I get an 'Beacon not found'?
Here is my index.ios.js code:
`/**
Sample React Native App
https://github.com/facebook/react-native
@flow
*/
//var React = require('react-native');
//var {DeviceEventEmitter} = React;
var Beacons = require('react-native-ibeacon');
var beaconRegion = {
identifier: 'TestBeacon',
uuid: 'F0018B9B-7509-4C31-A905-1A27D39C003C',
major: 52834,
minor: 18988,
};
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View,
TouchableHighlight,
DeviceEventEmitter,
TextInput,
} from 'react-native';
Beacons.requestAlwaysAuthorization();
/*
Code
*/
class beaconScanner extends Component {
_scanningForBeacon ()
{
//alert('Start');
//this.state.logInputText = "Starte Scanning";
// Request for authorization while the app is open
Beacons.startMonitoringForRegion(beaconRegion);
Beacons.startRangingBeaconsInRegion(beaconRegion);
}
render() {
return (
}
}
/*
Styles
*/
const styles = StyleSheet.create({
container: {
flex: 1,
//justifyContent: 'center',
//alignItems: 'center',
backgroundColor: '#C2C2C2',
},
buttonText: {
fontSize: 18,
color: 'white',
alignSelf: 'center'
},
button: {
height: 36,
backgroundColor: 'red',
borderRadius: 4,
marginBottom: 10,
marginRight: 20,
marginLeft: 20,
marginTop: 20,
justifyContent: 'center',
},
logFenster:
{
height: 300,
margin: 0,
marginTop: 0,
paddingTop: 30,
textAlign: 'center',
fontSize: 18,
backgroundColor: '#FFFFFF',
},
});
AppRegistry.registerComponent('beaconScanner', () => beaconScanner);
`
The text was updated successfully, but these errors were encountered: