2016-09-07 62 views
0

我的项目需要接收BLE广告包,并且在不连接BLE设备的情况下处理kCBAdvDataManufacturerData.BLE设备每秒发送广告包1次。在一个空视图控制器中,我收到广告打包每秒1次,但在我的控制器中显示BLE广告包数据时,我收到广告包的频率降低到1/4秒或更低。在此控制器中,我发送一些http请求并使用NSTimer 1更新UI每second.I时间处理kCBAdvDataManufacturerData在dispatch_sync(dispatch_get_global_queue(0,0),并且在mainqueue。 任何人更新UI有任何想法,以增加频率来接收BLE广告包?BLE广告包得到频率很低

回答

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

- 最后CONFIGURE_BROADCAST_INTERVAL_CHARACTERISTIC_将帮助你改变播放间隔。

+0

我解决了这个问题,无论如何感谢您的关注。 – HuangLW