iOS7的iBeacon初步使用

王朝学院·作者佚名  2016-08-27
窄屏简体版  字體: 小  |  中  |  大  |  超大  

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数组需要包含广播端的uuidfor(NSUUID *uuidin[APLDefaults sharedDefaults].supportedProximityUUIDs)

{

CLBeaconRegion*region =[[CLBeaconRegion alloc] initWithProximityUUID:uuid identifier:[uuid UUIDString]];

self.rangedRegions[region]=[NSArray array];

}for(CLBeaconRegion *regioninself.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

 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
© 2005- 王朝網路 版權所有 導航