Skip to content

Commit

Permalink
Merge pull request #433 from dinesharjani/xcode-13-compat-fix
Browse files Browse the repository at this point in the history
Fix for Xcode 13 Builds but retaining Xcode 12 and older compatibility
  • Loading branch information
philips77 authored Jun 24, 2021
2 parents b3f53a6 + 27f1583 commit 89e8dca
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,11 @@ internal struct PacketReceiptNotification {
self.report = report

// Get the peripheral object.
#if swift(>=5.5)
guard let peripheral = characteristic.service?.peripheral else { return }
#else
let peripheral = characteristic.service.peripheral
#endif

// Set the peripheral delegate to self.
peripheral.delegate = self
Expand All @@ -247,7 +251,11 @@ internal struct PacketReceiptNotification {
self.resetSent = false

// Get the peripheral object.
#if swift(>=5.5)
guard let peripheral = characteristic.service?.peripheral else { return }
#else
let peripheral = characteristic.service.peripheral
#endif

// Set the peripheral delegate to self.
peripheral.delegate = self
Expand Down Expand Up @@ -295,7 +303,11 @@ internal struct PacketReceiptNotification {
self.uploadStartTime = CFAbsoluteTimeGetCurrent()

// Get the peripheral object.
#if swift(>=5.5)
guard let peripheral = characteristic.service?.peripheral else { return }
#else
let peripheral = characteristic.service.peripheral
#endif

// Set the peripheral delegate to self.
peripheral.delegate = self
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ internal class DFUPacket: DFUCharacteristic {
*/
func sendFirmwareSize(_ size: DFUFirmwareSize) {
// Get the peripheral object
#if swift(>=5.5)
guard let peripheral = characteristic.service?.peripheral else { return }
#else
let peripheral = characteristic.service.peripheral
#endif

let data = Data()
+ size.softdevice.littleEndian
Expand All @@ -89,7 +93,11 @@ internal class DFUPacket: DFUCharacteristic {
*/
func sendFirmwareSize_v1(_ size: DFUFirmwareSize) {
// Get the peripheral object.
#if swift(>=5.5)
guard let peripheral = characteristic.service?.peripheral else { return }
#else
let peripheral = characteristic.service.peripheral
#endif

let data = Data() + size.application.littleEndian

Expand All @@ -107,7 +115,11 @@ internal class DFUPacket: DFUCharacteristic {
*/
func sendInitPacket(_ data: Data) {
// Get the peripheral object.
#if swift(>=5.5)
guard let peripheral = characteristic.service?.peripheral else { return }
#else
let peripheral = characteristic.service.peripheral
#endif

// Data may be sent in up-to-20-bytes packets.
var offset: UInt32 = 0
Expand Down Expand Up @@ -143,7 +155,11 @@ internal class DFUPacket: DFUCharacteristic {
func sendNext(_ prnValue: UInt16, packetsOf firmware: DFUFirmware,
andReportProgressTo progress: DFUProgressDelegate?, on queue: DispatchQueue) {
// Get the peripheral object.
#if swift(>=5.5)
guard let peripheral = characteristic.service?.peripheral else { return }
#else
let peripheral = characteristic.service.peripheral
#endif

// Some super complicated computations...
let bytesTotal = UInt32(firmware.data.count)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@ internal typealias VersionCallback = (_ major: UInt8, _ minor: UInt8) -> Void
self.report = report

// Get the peripheral object.
#if swift(>=5.5)
guard let peripheral = characteristic.service?.peripheral else { return }
#else
let peripheral = characteristic.service.peripheral
#endif

// Set the peripheral delegate to self.
peripheral.delegate = self
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,11 @@ import CoreBluetooth
self.report = report

// Get the peripheral object
#if swift(>=5.5)
guard let peripheral = service.peripheral else { return }
#else
let peripheral = service.peripheral
#endif

// Set the peripheral delegate to self
peripheral.delegate = self
Expand Down Expand Up @@ -194,7 +198,12 @@ import CoreBluetooth
// - we must be in the DFU mode already (otherwise the device would be useless...).
// Note: On iOS the Generic Access and Generic Attribute services (nor HID Service)
// are not returned during service discovery.
let services = service.peripheral.services
#if swift(>=5.5)
guard let peripheral = service.peripheral else { return false }
#else
let peripheral = service.peripheral
#endif
let services = peripheral.services
if services?.count == 1 {
return false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,11 @@ internal class ButtonlessDFU : NSObject, CBPeripheralDelegate, DFUCharacteristic
self.report = report

// Get the peripheral object.
#if swift(>=5.5)
guard let peripheral = characteristic.service?.peripheral else { return }
#else
let peripheral = characteristic.service.peripheral
#endif

// Set the peripheral delegate to self.
peripheral.delegate = self
Expand Down Expand Up @@ -207,7 +211,11 @@ internal class ButtonlessDFU : NSObject, CBPeripheralDelegate, DFUCharacteristic
self.report = report

// Get the peripheral object.
#if swift(>=5.5)
guard let peripheral = characteristic.service?.peripheral else { return }
#else
let peripheral = characteristic.service.peripheral
#endif

// Set the peripheral delegate to self.
peripheral.delegate = self
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,11 @@ internal class SecureDFUControlPoint : NSObject, CBPeripheralDelegate, DFUCharac
self.report = report

// Get the peripheral object.
#if swift(>=5.5)
guard let peripheral = characteristic.service?.peripheral else { return }
#else
let peripheral = characteristic.service.peripheral
#endif

// Set the peripheral delegate to self.
peripheral.delegate = self
Expand Down Expand Up @@ -380,7 +384,11 @@ internal class SecureDFUControlPoint : NSObject, CBPeripheralDelegate, DFUCharac
self.report = report

// Get the peripheral object.
#if swift(>=5.5)
guard let peripheral = characteristic.service?.peripheral else { return }
#else
let peripheral = characteristic.service.peripheral
#endif

// Set the peripheral delegate to self.
peripheral.delegate = self
Expand Down Expand Up @@ -409,7 +417,11 @@ internal class SecureDFUControlPoint : NSObject, CBPeripheralDelegate, DFUCharac
self.report = report

// Get the peripheral object.
#if swift(>=5.5)
guard let peripheral = characteristic.service?.peripheral else { return }
#else
let peripheral = characteristic.service.peripheral
#endif

// Set the peripheral delegate to self.
peripheral.delegate = self
Expand Down Expand Up @@ -439,7 +451,11 @@ internal class SecureDFUControlPoint : NSObject, CBPeripheralDelegate, DFUCharac
self.report = report

// Get the peripheral object.
#if swift(>=5.5)
guard let peripheral = characteristic.service?.peripheral else { return }
#else
let peripheral = characteristic.service.peripheral
#endif

// Set the peripheral delegate to self.
peripheral.delegate = self
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,16 @@ internal class SecureDFUPacket: DFUCharacteristic {
self.logger = logger

if #available(iOS 9.0, macOS 10.12, *) {
#if swift(>=5.5)
guard let peripheral = characteristic.service?.peripheral else {
packetSize = 20 // Default MTU is 23.
return
}
#else
let peripheral = characteristic.service.peripheral
#endif
// Make the packet size the first word-aligned value that's less than the maximum.
packetSize = UInt32(characteristic.service.peripheral.maximumWriteValueLength(for: .withoutResponse)) & 0xFFFFFFFC
packetSize = UInt32(peripheral.maximumWriteValueLength(for: .withoutResponse)) & 0xFFFFFFFC
if packetSize > 20 {
// MTU is 3 bytes larger than payload
// (1 octet for Op-Code and 2 octets for Att Handle).
Expand All @@ -79,7 +87,11 @@ internal class SecureDFUPacket: DFUCharacteristic {
*/
func sendInitPacket(_ data: Data) {
// Get the peripheral object.
#if swift(>=5.5)
guard let peripheral = characteristic.service?.peripheral else { return }
#else
let peripheral = characteristic.service.peripheral
#endif

// Data may be sent in up-to-20-bytes packets.
var offset: UInt32 = 0
Expand Down Expand Up @@ -114,7 +126,11 @@ internal class SecureDFUPacket: DFUCharacteristic {
func sendNext(_ prnValue: UInt16, packetsFrom range: Range<Int>, of firmware: DFUFirmware,
andReportProgressTo progress: DFUProgressDelegate?, on queue: DispatchQueue,
andCompletionTo complete: @escaping Callback) {
let peripheral = characteristic.service.peripheral
#if swift(>=5.5)
guard let peripheral = characteristic.service?.peripheral else { return }
#else
let peripheral = characteristic.service.peripheral
#endif
let objectData = firmware.data.subdata(in: range)
let objectSizeInBytes = UInt32(objectData.count)
let objectSizeInPackets = (objectSizeInBytes + packetSize - 1) / packetSize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,11 @@ import CoreBluetooth
self.report = report

// Get the peripheral object
#if swift(>=5.5)
guard let peripheral = service.peripheral else { return }
#else
let peripheral = service.peripheral
#endif

// Set the peripheral delegate to self
peripheral.delegate = self
Expand Down

0 comments on commit 89e8dca

Please sign in to comment.