Skip to content
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ DerivedData

Pods
Carthage
.swiftpm
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ internal final class AdvertisementService: NSObject {
internal var writeCallback: ((Characteristic, Data?) -> ())?

/// Callback called upon upcoming errors.
private var errorHandler: ((AdvertisementError) -> ())?
private var errorHandler: ((AdvertisementError?) -> ())?

/// Starts advertising peripheral with given configuration of services and characteristics.
internal func startAdvertising(_ peripheral: Peripheral<Advertisable>, errorHandler: ((AdvertisementError) -> ())?) {
internal func startAdvertising(_ peripheral: Peripheral<Advertisable>, errorHandler: ((AdvertisementError?) -> ())?) {
self.peripheral = peripheral
self.errorHandler = errorHandler
peripheralManager.startAdvertising(peripheral.advertisementData?.combined())
Expand Down Expand Up @@ -81,6 +81,7 @@ extension AdvertisementService: CBPeripheralManagerDelegate {
return
}
self.peripheral?.configuration.services.map({ $0.assignAdvertisementService() }).forEach(peripheralManager.add(_:))
errorHandler?(nil)
}

/// - SeeAlso: `CBPeripheralManagerDelegate`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public final class BluetoothAdvertisement {
/// - errorHandler: an error handler. Will be called only after unsuccessfull advertisement setup.
/// - SeeAlso: `AdvertisementError`
/// - SeeAlso: `Peripheral`
public func advertise(peripheral: Peripheral<Advertisable>, errorHandler: ((AdvertisementError) -> ())?) {
public func advertise(peripheral: Peripheral<Advertisable>, errorHandler: ((AdvertisementError?) -> ())?) {
advertisementService.startAdvertising(peripheral, errorHandler: errorHandler)
}

Expand Down
15 changes: 3 additions & 12 deletions Framework/Source Files/Connection/ConnectionService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,9 @@ extension ConnectionService {

/// Starts connection with passed device. Connection result is passed in handler closure.
internal func connect(_ peripheral: Peripheral<Connectable>, handler: @escaping (Peripheral<Connectable>, ConnectionError?) -> ()) {
if connectionHandler == nil {
connectionHandler = handler
}
do {
try centralManager.validateState()
peripherals.append(peripheral)
reloadScanning()
} catch let error {
if let error = error as? BluetoothError {
handler(peripheral, .bluetoothError(error))
}
}
connectionHandler = handler
peripherals.append(peripheral)
reloadScanning()
}

/// Disconnects given device.
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

let package = Package(
name: "BlueSwift",
platforms: [ .iOS(.v10) ],
platforms: [ .iOS(.v10), .macOS(.v11) ],
products: [
.library(
name: "BlueSwift",
Expand Down