我已经按照示例了解如何在这里使用react-native-beacons-manager:https://github.com/MacKentoch/react-native-beacons-manager/blob/master/examples/samples/monitoringAndRanging.ios.md 但即使我有一个信标设备,我也无法检测到该地区的任何信标。我在硬编码区域很困惑:
const region = {
identifier: 'Estimotes',
uuid: 'B9407F30-F5F8-466E-AFF9-25556B57FE6D'
};
这些标识符和UUID是什么?使用它是否安全,或者我应该在某处开始检测信标?这是我的相关代码,我省略了一些不相关的代码:
import Beacons from 'react-native-beacons-manager';
class HomeTab extends Component {
constructor(props) {
super(props);
var ds = new ListView.DataSource({
rowHasChanged: (r1, r2) => r1 !== r2 }
);
this.state = {
region: {
latitude: LATITUDE,
longitude: LONGITUDE,
latitudeDelta: LATITUDE_DELTA,
longitudeDelta: LONGITUDE_DELTA,
dataSource: ds.cloneWithRows([])
}
};
}
componentWillMount(){
Beacons.requestAlwaysAuthorization();
const region = {
identifier: 'Estimotes',
uuid: 'B9407F30-F5F8-466E-AFF9-25556B57FE6D'
};
Beacons.startMonitoringForRegion(region) // or like < v1.0.7: .startRangingBeaconsInRegion(identifier, uuid)
.then(() => console.log('Beacons monitoring started succesfully'))
.catch(error => console.log(`Beacons monitoring not started, error: ${error}`));
// Range for beacons inside the region
Beacons.startRangingBeaconsInRegion(region) // or like < v1.0.7: .startRangingBeaconsInRegion(identifier, uuid)
.then(() => console.log('Beacons ranging started succesfully'))
.catch(error => console.log(`Beacons ranging not started, error: ${error}`));
// update location to ba able to monitor:
Beacons.startUpdatingLocation();
}
componentDidMount(){
this.beaconsDidRangeEvent = DeviceEventEmitter.addListener(
'beaconsDidRange',
(data) => {
console.log('beaconsDidRange data: ', data);
}
);
this.beaconsDidRangeEvent = Beacons.BeaconsEventEmitter.addListener(
'beaconsDidRange',
(data) => {
console.log('beaconsDidRange data: ', data);
}
);
// monitoring events
this.regionDidEnterEvent = Beacons.BeaconsEventEmitter.addListener(
'regionDidEnter',
(data) => {
console.log('monitoring - regionDidEnter data: ', data);
}
);
}
}