#iOS开发笔记#如何接收iBeacon信号并读取其信息

iBeacon技术不多赘述,本文重点关注如何在iOS上扫描周围的iBeacon信号并读取信息,包括beacon设备的UUID,Major,Minor和当前距离。

0. 添加location权限


找到project目录下Supporting Files -> Info.plist -> 右键空白"Add Row" -> 输入“NSLocationWhenInUseUsageDescription”,value为提示信息,可以为空。

1. 添加CoreLocation.framework

Build Phases -> Link Binary With Libraries -> add "CoreLocation.framework"

2. 引入库CoreLocation/CoreLocation.h

#import <CoreLocation/CoreLocation.h>

3. 添加CLLocationManagerDelegate

@interface BeaconViewController : UITableViewController <CLLocationManagerDelegate>

4. 声明对象

@interface BeaconViewController : UITableViewController <CLLocationManagerDelegate>{
    CLLocationManager *_locationManager;<span style="white-space:pre">	</span>//
    CLBeaconRegion *_region;<span style="white-space:pre">			</span>//
    NSArray *_detectedBeacons;<span style="white-space:pre">			</span>//存放接收到的beacons
}

5. 初始化对象

MY_UUID为beacon的UUID,iOS只允许接收指定UUID的beacon信号。MY_REGION_IDENTIFIER自定义。
#pragma mark - Init Beacons
- (void) initLocationManager{
    if (!_locationManager) {
        _locationManager = [[CLLocationManager alloc] init];
        _locationManager.delegate = self;
        [self checkLocationAccessForRanging];
    }
}

- (void) initDetectedBeaconsList{
    if (!_detectedBeac
  • 3
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值