0

When my iOS (peripheral) starts advertising, I instantly re-run my app, at this point, my computer (central) was in middle of subscribing to a characteristic and writing to it.

Once my peripheral app finishes launching, something goes wrong (probably because central was previously trying to write to it) and my app crashes with this message:

*** Assertion failure in -[CBPeripheralManager respondToRequest:withResult:], /SourceCache/CoreBluetooth/CoreBluetooth-256/CBPeripheralManager.m:423

I never call "respondToRequest" in my code, all of my peripheral's characteristics are configured as follows (WriteWithoutResponse):

let properties: CBCharacteristicProperties = [CBCharacteristicProperties.Read, CBCharacteristicProperties.WriteWithoutResponse, CBCharacteristicProperties.Notify]
let permissions: CBAttributePermissions = [CBAttributePermissions.Readable, CBAttributePermissions.Writeable]

When I write to the characteristics from the Centra's end, I use:

writeValue(chunkOfData, forCharacteristic: charactristic, type: CBCharacteristicWriteType.WithoutResponse)

I'm not sure how to prevent this issue. Any ideas please?

Lee Andrew
  • 798
  • 7
  • 28
  • Are you sure? It is impossible to implement a peripheral role app that accepts data from the central without calling `respondToRequest:withResult:` Please show the code for your `CBPeripheralManagerDelegate` – Paulw11 Oct 19 '15 at 23:32
  • Well, I build an object by appending resquests[i].value to a variable, stop when I find a string indicating the end-of-a-certain-message and act accordingly. Works perfectly. – Lee Andrew Oct 19 '15 at 23:33
  • What is your `peripheralManager:didReceiveWriteRequests:` method? – Paulw11 Oct 19 '15 at 23:36
  • for request in requests { receiveBluetoothData(request.central, characteristic: request.characteristic, value: request.value!) } – Lee Andrew Oct 19 '15 at 23:38
  • Thats all I have there receiveBluetoothData is responsible for appending, and taking action accordingly. – Lee Andrew Oct 19 '15 at 23:38
  • Ok, so what is in that method? From the Apple programming guide - "Call the respondToRequest:withResult: method exactly once each time the peripheralManager:didReceiveReadRequest: delegate method is called", so you must call this method somewhere/ – Paulw11 Oct 19 '15 at 23:40
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/92787/discussion-between-lee-andrew-and-paulw11). – Lee Andrew Oct 19 '15 at 23:41

1 Answers1

0

From our discussion it seems that providing the CBPeripheralManagerOptionRestoreIdentifierKey and associated value when initialising the CBPeripheralManager but not implementing the state restoration methods caused the exception.

Paulw11
  • 108,386
  • 14
  • 159
  • 186