How does ibeacon work on background?

孤人 提交于 2019-12-11 13:24:47

问题


I want to create a order when someone enters into the iBeacon region on app background,but I have a problem when the app on background.

I know if user open "location" and "bluetooth" and enter into region, app will detect the ibeacon.But after entering into region, user open "bluetooth",the app can't receive the entry notification(sometime work) and can't invoke the function locationManager:(CLLocationManager *)manager didRangeBeacons:(NSArray *)beacons inRegion:(CLBeaconRegion *)region so the order can't be created.

Does anyone have experience on it?


回答1:


For more realistic and accurately get bluetooth state value, override its delegate to controller. Core bluetooth framework will help here to get desire accuracy.

Add <CoreBluetooth/CoreBluetooth.h> framework in project.

Use method

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

to check bluetooth is powered on?

Peripheral Manager State will gives you more details about peripheral state and related delegates.

So when ever device has turn on it's bluetooth, above delegate method will be called.

And here you can manually start to check for region updates.

For 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];
    }
}

The method startRangingBeaconsInRegion will invoke the method:

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


来源:https://stackoverflow.com/questions/28020472/how-does-ibeacon-work-on-background

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!