Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Found Beacon although it is powered off #36

Open
ghost opened this issue Jul 14, 2016 · 1 comment
Open

Found Beacon although it is powered off #36

ghost opened this issue Jul 14, 2016 · 1 comment

Comments

@ghost
Copy link

ghost commented Jul 14, 2016

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);

//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
}
);

}

render() {
return (

    <TextInput
    ref={component => this._textInput = component}
        style={styles.logFenster}
             multiline = {true}
             numberOfLines = {4}
             editable = {false}
             value= ':LOG:'
           />


    <TouchableHighlight style={styles.button}
      underlayColor='#99d9f4'
      onPress={this._scanningForBeacon}>
        <Text style={styles.buttonText}>Start scanning</Text>
    </TouchableHighlight>

  </View>
);

}
}

/*




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);
`

@ErikSvedin
Copy link

ErikSvedin commented Sep 7, 2016

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:

var subscription = DeviceEventEmitter.addListener(
'beaconsDidRange',
(data) => {
  if (data.beacons)
  {
    alert('FOUND: '+data.region.uuid);
    Beacons.stopMonitoringForRegion(data.region);
    Beacons.stopRangingBeaconsInRegion(data.region);
  }
  else {

    alert('No beacon found');

  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant