美文网首页
iOS iBeacon开发

iOS iBeacon开发

作者: zero616 | 来源:发表于2017-06-08 14:45 被阅读0次

1.在info.plist中添加

Privacy - Location Always Usage Description                 显示给用户看的信息    例如:将获取您的位置信息

Privacy - Location When In Use Usage Description        显示给用户看的信息    例如:将获取您的位置信息


2.添加以下头文件:

#import <CoreLocation/CoreLocation.h>

#import <CoreBluetooth/CoreBluetooth.h>


3.创建2个属性

@property(nonatomic,strong)CLBeaconRegion  *beaconRegion;

@property(nonatomic,strong)CLLocationManager  *locationManager;


4.初始化对象实例,并开始扫描指定UUID的Beacon

self.locationManager= [[CLLocationManageralloc]init];

self.locationManager.delegate=self;

if([[UIDevice  currentDevice].systemVersion  floatValue] >=8.0) {

          //请求允许定位通知

           [self.locationManager  requestWhenInUseAuthorization];

           //请求允许声音等通知

            [[UIApplication  sharedApplication]  registerUserNotificationSettings:   [UIUserNotificationSettings   settingsForTypes:UIUserNotificationTypeAlert  |  UIUserNotificationTypeBadge  |  UIUserNotificationTypeSound  categories:nil]];

           }

uuid是Beacon的UUID,此处为宏,identifier好像怎么设置都没影响,是一个字符串

self.beaconRegion= [[CLBeaconRegion  alloc] initWithProximityUUID:[[NSUUID  alloc] initWithUUIDString:uuid]  identifier:""];

//开始监听Beacon消息

[self.locationManager  startMonitoringForRegion:self.beaconRegion];

[self.locationManager  startRangingBeaconsInRegion:self.beaconRegion];

}


5.代理的回调方法一:进入Beacon范围内触发,后台模式也可以触发

- (void)locationManager:(CLLocationManager*)manager didEnterRegion:(CLRegion*)region {

//以下方法 目前我也未搞清楚有何用,不写也不影响的感觉

[self.locationManager  startRangingBeaconsInRegion:self.beaconRegion];

}


6.代理的回调方法二:获取Beacon的信息,例如RSSI,UUID,major,minor,accuracy(距离),后台模式不能触发,除了把整个APP设置后台一直运行

- (void)locationManager:(CLLocationManager*)manager didRangeBeacons:(NSArray *)beacons inRegion:(CLBeaconRegion*)region {

beacons是一个数组,一次性扫描到的beacon,大约1S回调一次这个方法

}


7.代理的回调方法三:离开Beacon范围内

- (void)locationManager:(CLLocationManager*)manager didExitRegion:(CLRegion*)region {

//以下方法 目前我也未搞清楚有何用,不写也不影响的感觉

[self.locationManager  startRangingBeaconsInRegion:self.beaconRegion];

}


注意:市场上有一些Beacon应用是可以同时搜索到Beacon的各参数,Beacon名称,传感器数据等。这里我猜测是同时运行了2种蓝牙搜索模式,BLE搜索,Beacon搜索,2个模式合并封装而成的。我也尝试过可以获取想要的各项数据。

相关文章

  • iOS 中 iBeacon 开发

    iOS 中 iBeacon 开发 iOS 中 iBeacon 开发

  • 开发使用 iBeacon 的 iOS 7 应用

    开发使用 iBeacon 的 iOS 7 应用 开发使用 iBeacon 的 iOS 7 应用

  • iBeacon开发学习资料整理

    开发使用 iBeacon 的 iOS 7 应用:http://www.cocoachina.com/industr...

  • iOS iBeacon开发

    1.在info.plist中添加 Privacy - Location Always Usage Descript...

  • iOS iBeacon开发

    应用场景 最近有个项目需求是,在展会的各个商家展位上配置iBeacon设备,当用户(手机上安装公司APP)进入ib...

  • iOS 中 iBeacon 开发

    iBeacon 介绍 iBeacon 是苹果公司2013年9月发布的移动设备用OS(iOS7)上配备的新功能。其工...

  • iOS 中 iBeacon 开发

    什么是iBeacon? iBeacon 是苹果公司2013年9月发布的移动设备用OS(iOS7)上配备的新功能。其...

  • iOS 中 iBeacon 开发

    什么是iBeacon? iBeacon 是苹果公司2013年9月发布的移动设备用OS(iOS7)上配备的新功能。其...

  • iBeacon 应用实例

    iBeacon是什么?     苹果官方对iBeacon的描述:iBeacon是iOS 7推出的一项技术,可为AP...

  • iBeacon相关知识

    从iBeacon开始 入门iBeacon概述 在iOS 7中引入的iBeacon是一项令人兴奋的技术,可以实现新的...

网友评论

      本文标题:iOS iBeacon开发

      本文链接:https://www.haomeiwen.com/subject/xcxtqxtx.html