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

tweaks due to ios update #407

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
7 changes: 6 additions & 1 deletion Source/CentralManagerRestoredState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,12 @@ public struct CentralManagerRestoredState: CentralManagerRestoredStateType {
let cbServices = arrayOfAnyObjects.flatMap { $0 as? CBService }
#endif

return cbServices.map { Service(peripheral: centralManager.retrievePeripheral(for: $0.peripheral),
return cbServices.compactMap {
guard let peripheral = $0.peripheral else {
return nil
}

return Service(peripheral: centralManager.retrievePeripheral(for: peripheral),
service: $0) }
}
}
7 changes: 5 additions & 2 deletions Source/Characteristic.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,11 @@ public class Characteristic {
self.service = service
}

convenience init(characteristic: CBCharacteristic, peripheral: Peripheral) {
let service = Service(peripheral: peripheral, service: characteristic.service)
convenience init?(characteristic: CBCharacteristic, peripheral: Peripheral) {
guard let bluetoothService = characteristic.service else {
return nil
}
let service = Service(peripheral: peripheral, service: bluetoothService)
self.init(characteristic: characteristic, service: service)
}

Expand Down
11 changes: 8 additions & 3 deletions Source/Descriptor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,14 @@ public class Descriptor {
self.characteristic = characteristic
}

convenience init(descriptor: CBDescriptor, peripheral: Peripheral) {
let service = Service(peripheral: peripheral, service: descriptor.characteristic.service)
let characteristic = Characteristic(characteristic: descriptor.characteristic, service: service)
convenience init?(descriptor: CBDescriptor, peripheral: Peripheral) {
guard let bluetoothService = descriptor.characteristic?.service,
let bluetoothCharacteristic = descriptor.characteristic else {
return nil
}
let service = Service(peripheral: peripheral, service: bluetoothService)
let characteristic = Characteristic(characteristic: bluetoothCharacteristic,
service: service)
self.init(descriptor: descriptor, characteristic: characteristic)
}

Expand Down
16 changes: 16 additions & 0 deletions Source/Peripheral.swift
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,10 @@ public class Peripheral {
.map { [weak self] (cbCharacteristic, error) -> Characteristic in
guard let strongSelf = self else { throw BluetoothError.destroyed }
let characteristic = characteristic ?? Characteristic(characteristic: cbCharacteristic, peripheral: strongSelf)
guard let characteristic = characteristic else {
throw BluetoothError.unknownWriteType
}

if let error = error {
throw BluetoothError.characteristicWriteFailed(characteristic, error)
}
Expand Down Expand Up @@ -499,6 +503,9 @@ public class Peripheral {
.map { [weak self] (cbCharacteristic, error) -> Characteristic in
guard let strongSelf = self else { throw BluetoothError.destroyed }
let characteristic = characteristic ?? Characteristic(characteristic: cbCharacteristic, peripheral: strongSelf)
guard let characteristic = characteristic else {
throw BluetoothError.unknownWriteType
}
if let error = error {
throw BluetoothError.characteristicReadFailed(characteristic, error)
}
Expand Down Expand Up @@ -569,6 +576,9 @@ public class Peripheral {
.map { [weak self] (cbCharacteristic, error) -> Characteristic in
guard let strongSelf = self else { throw BluetoothError.destroyed }
let characteristic = Characteristic(characteristic: cbCharacteristic, peripheral: strongSelf)
guard let characteristic = characteristic else {
throw BluetoothError.unknownWriteType
}
if let error = error {
throw BluetoothError.characteristicSetNotifyValueFailed(characteristic, error)
}
Expand Down Expand Up @@ -638,6 +648,9 @@ public class Peripheral {
.map { [weak self] (cbDescriptor, error) -> Descriptor in
guard let strongSelf = self else { throw BluetoothError.destroyed }
let descriptor = descriptor ?? Descriptor(descriptor: cbDescriptor, peripheral: strongSelf)
guard let descriptor = descriptor else {
throw BluetoothError.unknownWriteType
}
if let error = error {
throw BluetoothError.descriptorWriteFailed(descriptor, error)
}
Expand Down Expand Up @@ -667,6 +680,9 @@ public class Peripheral {
.map { [weak self] (cbDescriptor, error) -> Descriptor in
guard let strongSelf = self else { throw BluetoothError.destroyed }
let descriptor = descriptor ?? Descriptor(descriptor: cbDescriptor, peripheral: strongSelf)
guard let descriptor = descriptor else {
throw BluetoothError.unknownWriteType
}
if let error = error {
throw BluetoothError.descriptorReadFailed(descriptor, error)
}
Expand Down