ibeacon如何在后台工作?

时间:2015-01-19 08:25:09

标签: ios bluetooth ibeacon

我想在有人进入应用程序的iBeacon区域时创建订单 背景,但我在背景上的应用程序时遇到问题。

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

有没有人有经验呢?

1 个答案:

答案 0 :(得分:0)

为了更真实,更准确地获取蓝牙状态值,请将其委托覆盖到控制器。核心蓝牙框架将有助于获得渴望的准确性。

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

使用方法

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

检查蓝牙是否开机?

Peripheral Manager State 会为您提供有关外围设备状态和相关代表的更多详细信息。

因此,当设备打开蓝牙时,将调用上面的委托方法。

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

对于Exmaple:

_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;