Skip to content

Commit

Permalink
Update BKCBPeripheralDelegate to actually recieve delegate call backs
Browse files Browse the repository at this point in the history
  • Loading branch information
David Rees committed Oct 18, 2016
1 parent 2819a70 commit 4de586c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 49 deletions.
79 changes: 34 additions & 45 deletions Source/BKCBPeripheralDelegateProxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ import CoreBluetooth

internal protocol BKCBPeripheralDelegate: class {
func peripheralDidUpdateName(_ peripheral: CBPeripheral)
func peripheral(_ peripheral: CBPeripheral, didDiscoverServices error: NSError?)
func peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsForService service: CBService, error: NSError?)
func peripheral(_ peripheral: CBPeripheral, didUpdateValueForCharacteristic characteristic: CBCharacteristic, error: NSError?)
func peripheral(_ peripheral: CBPeripheral, didDiscoverServices error: Error?)
func peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsFor service: CBService, error: Error?)
func peripheral(_ peripheral: CBPeripheral, didUpdateValueFor characteristic: CBCharacteristic, error: Error?)
}

internal class BKCBPeripheralDelegateProxy: NSObject, CBPeripheralDelegate {
Expand All @@ -51,57 +51,46 @@ internal class BKCBPeripheralDelegateProxy: NSObject, CBPeripheralDelegate {
delegate?.peripheralDidUpdateName(peripheral)
}

internal func peripheral(_ peripheral: CBPeripheral, didModifyServices invalidatedServices: [CBService]) {
// print("peripheral: \(peripheral) didModifyServices invalidatedServices: \(invalidatedServices)")
}

internal func peripheralDidUpdateRSSI(_ peripheral: CBPeripheral, error: NSError?) {
// print("peripheralDidUpdateRSSI: \(peripheral), error: \(error)")
}

internal func peripheral(_ peripheral: CBPeripheral, didReadRSSI RSSI: NSNumber, error: NSError?) {
// print("peripheral: \(peripheral) didReadRSSI: \(RSSI), error: \(error)")
}

internal func peripheral(_ peripheral: CBPeripheral, didDiscoverServices error: NSError?) {
// print("peripheral: \(peripheral) didDiscoverServices error: \(error)")
internal func peripheral(_ peripheral: CBPeripheral, didDiscoverServices error: Error?) {
delegate?.peripheral(peripheral, didDiscoverServices: error)
}

internal func peripheral(_ peripheral: CBPeripheral, didDiscoverIncludedServicesFor service: CBService, error: NSError?) {
// print("peripheral: \(peripheral) didDiscoverIncludedServicesForService: \(service), error: \(error)")
internal func peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsFor service: CBService, error: Error?) {
delegate?.peripheral(peripheral, didDiscoverCharacteristicsFor: service, error: error)
}

internal func peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsFor service: CBService, error: NSError?) {
// print("peripheral: \(peripheral) didDiscoverCharacteristicsForService: \(service), error: \(error)")
delegate?.peripheral(peripheral, didDiscoverCharacteristicsForService: service, error: error)

internal func peripheral(_ peripheral: CBPeripheral, didUpdateValueFor characteristic: CBCharacteristic, error: Error?) {
delegate?.peripheral(peripheral, didUpdateValueFor: characteristic, error: error)
}

internal func peripheral(_ peripheral: CBPeripheral, didUpdateValueFor characteristic: CBCharacteristic, error: NSError?) {
// print("peripheral: \(peripheral) didUpdateValueForCharacteristic: \(characteristic), error: \(error)")
delegate?.peripheral(peripheral, didUpdateValueForCharacteristic: characteristic, error: error)

internal func peripheral(_ peripheral: CBPeripheral, didReadRSSI RSSI: NSNumber, error: Error?) {

}

internal func peripheral(_ peripheral: CBPeripheral, didWriteValueFor characteristic: CBCharacteristic, error: NSError?) {
// print("peripheral: \(peripheral), didWriteValueForCharacteristic: \(characteristic), error: \(error)")

@nonobjc
internal func peripheral(_ peripheral: CBPeripheral, didWriteValueFor descriptor: CBDescriptor, error: Error?) {

}

internal func peripheral(_ peripheral: CBPeripheral, didUpdateNotificationStateFor characteristic: CBCharacteristic, error: NSError?) {
// print("peripheral: \(peripheral) didUpdateNotificationStateForCharacteristic: \(characteristic), error: \(error)")

@nonobjc
internal func peripheral(_ peripheral: CBPeripheral, didUpdateValueFor descriptor: CBDescriptor, error: Error?) {

}

internal func peripheral(_ peripheral: CBPeripheral, didDiscoverDescriptorsFor characteristic: CBCharacteristic, error: NSError?) {
// print("peripheral: \(peripheral) didDiscoverDescriptorsForCharacteristic: \(characteristic), error: \(error)")
internal func peripheral(_ peripheral: CBPeripheral, didDiscoverIncludedServicesFor service: CBService, error: Error?) {

}

@nonobjc
internal func peripheral(_ peripheral: CBPeripheral, didUpdateValueFor descriptor: CBDescriptor, error: NSError?) {
// print("peripheral: \(peripheral) didUpdateValueForDescriptor: \(descriptor), error: \(error)")

internal func peripheral(_ peripheral: CBPeripheral, didWriteValueFor characteristic: CBCharacteristic, error: Error?) {

}

@nonobjc
internal func peripheral(_ peripheral: CBPeripheral, didWriteValueFor descriptor: CBDescriptor, error: NSError?) {
// print("peripheral: \(peripheral) didWriteValueForDescriptor: \(descriptor), error: \(error)")

internal func peripheral(_ peripheral: CBPeripheral, didDiscoverDescriptorsFor characteristic: CBCharacteristic, error: Error?) {

}

internal func peripheral(_ peripheral: CBPeripheral, didUpdateNotificationStateFor characteristic: CBCharacteristic, error: Error?) {

}

}
9 changes: 5 additions & 4 deletions Source/BKRemotePeripheral.swift
Original file line number Diff line number Diff line change
Expand Up @@ -145,32 +145,33 @@ public class BKRemotePeripheral: BKRemotePeer, BKCBPeripheralDelegate {
peripheralDelegate?.remotePeripheral(self, didUpdateName: name!)
}

internal func peripheral(_ peripheral: CBPeripheral, didDiscoverServices error: NSError?) {
internal func peripheral(_ peripheral: CBPeripheral, didDiscoverServices error: Error?) {
guard let services = peripheral.services else {
return
}
for service in services {
if service.characteristics != nil {
self.peripheral(peripheral, didDiscoverCharacteristicsForService: service, error: nil)
self.peripheral(peripheral, didDiscoverCharacteristicsFor: service, error: nil)
} else {
peripheral.discoverCharacteristics(configuration!.characteristicUUIDsForServiceUUID(service.uuid), for: service)
}
}
}

internal func peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsForService service: CBService, error: NSError?) {
internal func peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsFor service: CBService, error: Error?) {
guard service.uuid == configuration!.dataServiceUUID, let dataCharacteristic = service.characteristics?.filter({ $0.uuid == configuration!.dataServiceCharacteristicUUID }).last else {
return
}
characteristicData = dataCharacteristic
peripheral.setNotifyValue(true, for: dataCharacteristic)
}

internal func peripheral(_ peripheral: CBPeripheral, didUpdateValueForCharacteristic characteristic: CBCharacteristic, error: NSError?) {
internal func peripheral(_ peripheral: CBPeripheral, didUpdateValueFor characteristic: CBCharacteristic, error: Error?) {
guard characteristic.uuid == configuration!.dataServiceCharacteristicUUID else {
return
}
handleReceivedData(characteristic.value!)
}


}

0 comments on commit 4de586c

Please sign in to comment.