ibeacon如何在后台工作?

我想创build一个订单,当有人进入应用程序背景上的iBeacon区域,但我有一个问题,当在后台的应用程序。

我知道如果用户打开“位置”和“蓝牙”进入区域,应用程序将检测到ibeacon.But进入区域后,用户打开“蓝牙”,应用程序无法接收到通知(有时工作),可以调用函数locationManager:(CLLocationManager *)manager didRangeBeacons:(NSArray *)beacons inRegion:(CLBeaconRegion *)region所以无法创build订单。

有没有人有经验呢?

为了更真实和准确地获取蓝牙状态值,请将其代理重写到控制器。 核心蓝牙框架将有助于在这里获得欲望的准确性。

在项目中添加<CoreBluetooth/CoreBluetooth.h>框架。

使用方法

- (void)peripheralManagerDidUpdateState:(CBPeripheralManager *)peripheral;

检查蓝牙是否开机?

外设pipe理器状态会给你更多关于外设状态和相关代表的细节。

所以,当设备打开它的蓝牙,上面的委托方法将被调用。

在这里你可以手动开始检查区域更新。

例如:

 _locationManager = [[CLLocationManager alloc] init]; [_locationManager setDelegate:self]; _beaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID:uuid identifier:<Identifier>]; - (void)peripheralManagerDidUpdateState:(CBPeripheralManager *)peripheral { if (peripheral.state == CBPeripheralStateConnected) { [self.locationManager startRangingBeaconsInRegion:self.beaconRegion]; } } 

startRangingBeaconsInRegion方法将调用该方法:

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