您的位置:首页 > 其它

iBeacon技术笔记

2015-06-05 15:50 337 查看
#pragma mark - CLLocationManagerDelegate

//剩下的就是通过CLLocationManagerDelegate中的各个方法来获取监控区域内的所有CLBeacon基站,进入或退出某个Beacon区域,计算举例某个CLBeacon的距离等。

/*startMonioringForRegion方法调用后,如果手机监测到进入或者离开一个iBeacon基站区域,delegate就会调用这两个方法

locationManager:didEnterRegion:

locationManager:didExitRegion:

*/

/*

然后可以在locationManager:didEnterRegion:方法中调用[_locationManager startRangingBeaconsInRegion:_ibeaconRegion];来开启Ranging模式。

当离开、进入一个iBeacon区域或者于基站距离发生变化时,location Manger就会调用didRangeBeacons:inRegion:方法

*/

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

//

// UILocalNotification *notification = [UILocalNotification new];

//

// // Notification details

// // notification.alertBody = [NSString stringWithFormat:@"Entered beacon region for UUID: %@",region.proximityUUID.UUIDString]; // Major and minor are not available at the monitoring stage

// // notification.alertAction = NSLocalizedString(@"View Details", nil);

// // notification.soundName = UILocalNotificationDefaultSoundName;

//

// notification.alertBody = @"Enter region notification";

// [[UIApplication sharedApplication] presentLocalNotificationNow:notification];

//

// [self.beaconManager startRangingBeaconsInRegion:self.region];

//

//}

//该方法传递了两个参数,(NSArray *)beacons和(CLBeaconRegion *)region。这个beacons数组里的元素是按照距离排序的,所以取出数组中的第一个beacon就是离我们最近的那个ibeacons基站(当然这里也会有误差,不能保证真实距离就是最短的)

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

//

// if ([beacons count] > 0) {

//

// CLBeacon *nearestExhibit = [beacons firstObject];

// /*

// CLProximity 枚举:划分距离

// CLProximityUnknown,

// CLProximityImmediate,

// CLProximityNear,离iBeacon设备最近 10米左右

// CLProximityFar

//

// CLBeacons类中有如下几个属性:

// proximityUUID, major, minor, proximity, accuracy, rssi.

// 从远到近分别是CLProximityUnknown, CLProximityFar, CLProximityNear, CLProximityImmediate.

// accuracy(CLLocationAccuracy)表示以米为单位的精度

// rssi表示接受到的信号的强度

// */

// if (CLProximityNear == nearestExhibit.proximity) {

//

//

//

// } else {

//

//

//

// }

// // peripheralManagerDidUpdateStat

// // CBPeripheralManager

// }

//}

#pragma mark - Local notifications

#pragma mark - 本地通知

/*

UILocalNotification *notification = [UILocalNotification new];

notification.alertBody = @"Enter region notification";

[[UIApplication sharedApplication] presentLocalNotificationNow:notification];

*/

//- (void)viewWillAppear:(BOOL)animated{

// [super viewWillAppear:animated];

//

// if (!peripheralManager)

// {

// peripheralManager = [[CBPeripheralManager alloc] initWithDelegate:self queue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)];

// }

// else

// {

// peripheralManager.delegate = self;

// }

//

//}

//#pragma mark - CBPeripheralManagerDelegate method

//- (void)peripheralManagerDidUpdateState:(CBPeripheralManager *)peripheral{

//

//}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: