iOS7的iBeacon初步使用
2024-10-20 00:40:11
iBeacon是iOS7的新增的功能,通过BLE实现室内定位,精确到厘米级别。
测试使用两台iPhone(支持BLE),一台作为iBeacon基站广播信号,代码使用官方源码AirLocate,另外一台作为接收端,直接使用的是App Store下载的AirLocate)。
1、广播端主要代码
NSDictionary *peripheralData = nil;
region = [[CLBeaconRegion alloc] initWithProximityUUID:self.uuid major:[self.major shortValue]
minor:[self.minor shortValue] identifier:BeaconIdentifier];
peripheralData = [region peripheralDataWithMeasuredPower:power]; // The region's peripheral data contains the CoreBluetooth-specific data we need to advertise.
if(peripheralData)
{
//开始广播
[peripheralManager startAdvertising:peripheralData];
}
2、接收端主要代码
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self; //接收端的uuid数组需要包含广播端的uuid
for (NSUUID *uuid in [APLDefaults sharedDefaults].supportedProximityUUIDs)
{
CLBeaconRegion *region = [[CLBeaconRegion alloc] initWithProximityUUID:uuid identifier:[uuid UUIDString]];
self.rangedRegions[region] = [NSArray array];
} for (CLBeaconRegion *region in self.rangedRegions)
{
[self.locationManager startRangingBeaconsInRegion:region];
}
官方源码AirLocate:https://developer.apple.com/library/ios/samplecode/AirLocate/Introduction/Intro.html
App Store地址:https://itunes.apple.com/cn/app/airlocate/id716260068?mt=8
最新文章
- dotnet webapi 中添加Swagger文档
- 面试准备 - HashTable 的C#实现 开放地址法
- tomee.xml
- C# 如何使用 svcutil.exe 创建 WCF 客户端代码
- hiho_1050_树中的最长路
- New Distinct Substrings
- 这几天阅读的shadowgun的几个shader
- struts2框架的核心内容
- android 学习之RecyclerView
- 一天带你入门到放弃vue.js(二)
- Nginx调试入门
- 自动生成Excel 报表工具类
- visual studio 2017 installer 安装包的安装必备组件设置
- 扩展欧几里得,解线性同余方程 逆元 poj1845
- python面试题~反射,元类,单例
- java 冒泡排序 二分查找 选择排序 插入排序
- 【RF库XML测试】测试的XML文件说明
- mysql查询操作1
- Devexpress 百分号显示格式
- 对sssp项目搭建的补充,总错误处理。