BLE广告包的频率变得非常低

时间:2016-09-07 03:54:56

标签: ios bluetooth-lowenergy

我的项目需要接收BLE广告包,并在不连接BLE设备的情况下处理kCBAdvDataManufacturerData。BLE设备每秒发送1次广告包。在一个空的viewcontroller中,我每秒收到广告包1次,但在我的在我显示BLE广告包数据的控制器中,我收到广告包的频率减少到1次/ 4秒或更低。在这个控制器中,我发送一些http请求并使用NSTimer每秒1次更新UI。我在dispatch_sync中处理kCBAdvDataManufacturerData (dispatch_get_global_queue(0,0),并在mainqueue中更新UI。 有人有任何想法增加接收BLE广告包的频率吗?

1 个答案:

答案 0 :(得分:0)

-1。首先,您需要启动发现。

-(void)startDiscovery
{
if (self.mBtmanager == nil) {
  _mScanState = false;
    self.mBtmanager = [[CBCentralManager alloc] initWithDelegate:self queue:nil];
    self.mBtmanager.delegate = self;
}    
if (self.mBtmanager.state != CBCentralManagerStatePoweredOn) {
    _mScanState = true;
}
    NSDictionary *scanOption = @{CBCentralManagerScanOptionAllowDuplicatesKey:@YES};
[self.mBtmanager scanForPeripheralsWithServices:[[NSArray alloc] initWithObjects:[CBUUID UUIDWithString:JAALEE_ADV_SERVICE_UUID_STRING], nil] options:scanOption];
}

- 2.您需要连接Beacon。

-(void)startConnectDevice:(CBPeripheral*)peripheral
{
peripheral.delegate = self;
[self.mBtmanager connectPeripheral:peripheral options:nil];
} 

-3。然后使用writeServicesUUID

更改广播间隔
 [peripheral writeValue:value forCharacteristic:characteristic type:CBCharacteristicWriteWithResponse];

-finally CONFIGURE_BROADCAST_INTERVAL_CHARACTERISTIC_会帮助你。