首页 > 其他 > 详细

iOS7的iBeacon初步使用

时间:2014-03-01 05:11:54      阅读:677      评论:0      收藏:0      [点我收藏+]

iBeacon是iOS7的新增的功能,通过BLE实现室内定位,精确到厘米级别。

测试使用两台iPhone(支持BLE),一台作为iBeacon基站广播信号,代码使用官方源码AirLocate,另外一台作为接收端,直接使用的是App Store下载的AirLocate)。

1、广播端主要代码

bubuko.com,布布扣
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];
     }
bubuko.com,布布扣

bubuko.com,布布扣

2、接收端主要代码

bubuko.com,布布扣
  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];
    }
bubuko.com,布布扣

 bubuko.com,布布扣

官方源码AirLocate:https://developer.apple.com/library/ios/samplecode/AirLocate/Introduction/Intro.html

App Store地址:https://itunes.apple.com/cn/app/airlocate/id716260068?mt=8

iOS7的iBeacon初步使用,布布扣,bubuko.com

iOS7的iBeacon初步使用

原文:http://www.cnblogs.com/geweb/p/AirLocate.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!