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
新聞熱點
疑難解答