How to fix CBPeripheralManager's transmit queu

2019-08-09 04:22发布

问题:

I have a problem in CBPeripheralManager's method.

- (BOOL)updateValue:(NSData *)value forCharacteristic:(CBMutableCharacteristic *)characteristic onSubscribedCentrals:(NSArray *)centrals

According to Apple documentation, It will return YES if the update could be sent, or NO if the underlying transmit queue is full.

And I am getting NO. How should I fix this?

回答1:

When the output queue is full, you need to delay sending the response.

The worker queue scheme. The easiest way to solve this is by creating a worker queue where you insert the chunks of data you want to send and create a dispatcher block that takes the items and sends them out. When the queue is full, the current chunk is placed back on the head of the queue and after receiving the peripheralManagerIsReadyToUpdateSubscribers: you try to send again. If the central is disconnected or the connection is broken for some other reason, you should cancel all sending.