Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

endOfDataMark in BKConfiguration can be set to nil #125

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Source/BKCentral.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion Source/BKConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Source/BKPeer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down
3 changes: 2 additions & 1 deletion Source/BKPeripheral.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 ])
}

Expand Down
6 changes: 5 additions & 1 deletion Source/BKRemotePeer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down