我在这里遵循了如何使用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);
}
);
}
}
我也有这个问题。 启动MonitoringForRegion -> 成功。我使用特定信标的uuid。我的信标不是“Estimotes”,而是“bluebeacon” 但是,没有在函数“beaconsDidRange”后面输入。 请帮忙。