【问题标题】:How does ibeacon work on background?ibacon 如何在后台工作?
【发布时间】:2015-01-19 08:25:09
【问题描述】:

我想在应用上有人进入 iBeacon 区域时创建一个订单 后台,但是当应用程序在后台时出现问题。

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

有人有这方面的经验吗?

【问题讨论】:

    标签: ios bluetooth ibeacon


    【解决方案1】:

    为了更真实、更准确地获取蓝牙状态值,请覆盖其对控制器的委托。核心蓝牙框架将帮助在这里获得所需的准确性。

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

    使用方法

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

    检查蓝牙是否开机?

    Peripheral Manager State 将为您提供有关外围状态和相关委托的更多详细信息。

    所以当任何设备打开它的蓝牙时,上面的委托方法就会被调用。

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

    例如:

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

    【讨论】:

    猜你喜欢
    • 2014-06-18
    • 2019-04-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-23
    • 2020-11-06
    相关资源
    最近更新 更多