react-native-beacons-manager在Android上的使用 --工作笔记

本文介绍了如何在React Native项目中使用react-native-beacons-manager库进行iBeacon扫描。在Android上,必须获取位置权限并正确配置AndroidManifest.xml文件,否则beacon搜索结果将为空。
摘要由CSDN通过智能技术生成

github地址

npm install react-native-beacons-manager

import React, {
   Component} from 'react';
import {
   
  Text,
  View,
  DeviceEventEmitter,
  FlatList,
  StyleSheet,
  PermissionsAndroid,
  TouchableOpacity,
} from 'react-native';
import Beacons from 'react-native-beacons-manager';

export default class BeaconsManager extends Component {
   
  constructor(props) {
   
    super(props);
    this.state = {
   
      // region information
      uuidRef: null,
      identifier: 'TEST BEACON 1',
      // React Native ListView datasource initialization
      dataSource: [],
    };

  componentWillMount() {
   
    // 告诉该库检测beacon
    Beacons.detectIBeacons();

    const {
   identifier, uuid} = this.state;
    const FBeacons = {
   identifier, uuid};
    Beacons.startRangingBeaconsInRegion(FBeacons)
      .then(() => console.log('Beacons ranging started succesfully')) //启用成功
      .catch(error =>
        console.log(`Beacons ranging not started, error: ${
     error}`), //启用失败
      );
  }
  componentDidMount() {
   
    // component state aware here - attach events
    //获取周围的beacon数据
    DeviceEventEmitter.addListener('beaconsDidRange', data => {
   
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值