diff --git a/Source/BKCentral.swift b/Source/BKCentral.swift index 64a9a2a..8b98be1 100644 --- a/Source/BKCentral.swift +++ b/Source/BKCentral.swift @@ -314,12 +314,13 @@ public class BKCentral: BKPeer, BKCBCentralManagerStateDelegate, BKConnectionPoo } } - internal override func sendData(_ data: Data, toRemotePeer remotePeer: BKRemotePeer) -> Bool { + internal override func sendData(_ data: Data?, toRemotePeer remotePeer: BKRemotePeer) -> Bool { guard let remotePeripheral = remotePeer as? BKRemotePeripheral, let peripheral = remotePeripheral.peripheral, let characteristic = remotePeripheral.characteristicData else { return false } + guard let data = data else { return true } peripheral.writeValue(data, for: characteristic, type: .withoutResponse) return true } diff --git a/Source/BKConfiguration.swift b/Source/BKConfiguration.swift index 56357d0..165de29 100644 --- a/Source/BKConfiguration.swift +++ b/Source/BKConfiguration.swift @@ -39,7 +39,7 @@ public class BKConfiguration { public var dataServiceCharacteristicUUID: CBUUID /// Data used to indicate that no more data is coming when communicating. - public var endOfDataMark: Data + public var endOfDataMark: Data? /// Data used to indicate that a transfer was cancellen when communicating. public var dataCancelledMark: Data diff --git a/Source/BKPeer.swift b/Source/BKPeer.swift index d43bd9b..50a75bb 100644 --- a/Source/BKPeer.swift +++ b/Source/BKPeer.swift @@ -100,7 +100,7 @@ public class BKPeer { } } - internal func sendData(_ data: Data, toRemotePeer remotePeer: BKRemotePeer) -> Bool { + internal func sendData(_ data: Data?, toRemotePeer remotePeer: BKRemotePeer) -> Bool { fatalError("Function must be overridden by subclass") } diff --git a/Source/BKPeripheral.swift b/Source/BKPeripheral.swift index b974314..d8a8fa1 100644 --- a/Source/BKPeripheral.swift +++ b/Source/BKPeripheral.swift @@ -160,10 +160,11 @@ public class BKPeripheral: BKPeer, BKCBPeripheralManagerDelegate, BKAvailability } } - internal override func sendData(_ data: Data, toRemotePeer remotePeer: BKRemotePeer) -> Bool { + internal override func sendData(_ data: Data?, toRemotePeer remotePeer: BKRemotePeer) -> Bool { guard let remoteCentral = remotePeer as? BKRemoteCentral else { return false } + guard let data = data else { return true } return peripheralManager.updateValue(data, for: characteristicData, onSubscribedCentrals: [ remoteCentral.central ]) } diff --git a/Source/BKRemotePeer.swift b/Source/BKRemotePeer.swift index 6d9b38d..2146a57 100644 --- a/Source/BKRemotePeer.swift +++ b/Source/BKRemotePeer.swift @@ -56,7 +56,11 @@ public class BKRemotePeer: Equatable { } internal func handleReceivedData(_ receivedData: Data) { - if receivedData == configuration!.endOfDataMark { + guard let endOfDataMark = configuration!.endOfDataMark else { + delegate?.remotePeer(self, didSendArbitraryData: receivedData) + return + } + if receivedData == endOfDataMark { if let finalData = data { delegate?.remotePeer(self, didSendArbitraryData: finalData) }