Skip to content

Commit

Permalink
Add disconnect method and prevent stop scanning when connect to device
Browse files Browse the repository at this point in the history
  • Loading branch information
bgoncal committed Jul 16, 2024
1 parent 44786ae commit b7a993c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Improv-iOS.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |spec|
spec.name = "Improv-iOS"
spec.version = "0.0.3"
spec.version = "0.0.4"
spec.summary = "Easily detect and connect Improv devices to WiFi networks in iOS"
spec.description = "This library abstracts the bluetooth scanning for Improv devices and allow you to connect them to WiFi networks"
spec.author = "Improv"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
<key>Improv-iOS.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>1</integer>
<integer>0</integer>
</dict>
<key>Improve-iOS-Demo.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
<integer>1</integer>
</dict>
</dict>
</dict>
Expand Down
5 changes: 5 additions & 0 deletions Improv-iOS/BluetoothManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ protocol BluetoothManagerProtocol {
func scan()
func stopScan()
func connectToDevice(_ peripheral: CBPeripheral)
func disconnectFromDevice(_ peripheral: CBPeripheral)
func identifyDevice()
func sendWifi(ssid: String, password: String)
}
Expand Down Expand Up @@ -63,6 +64,10 @@ final class BluetoothManager: NSObject, BluetoothManagerProtocol {
enqueueOperation(Connect(device: peripheral))
}

func disconnectFromDevice(_ peripheral: CBPeripheral) {
centralManager.cancelPeripheralConnection(peripheral)
}

func identifyDevice() {
guard let gatt = bluetoothGatt else {
fatalError("Not Connected to a Device!")
Expand Down
6 changes: 5 additions & 1 deletion Improv-iOS/ImprovManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public protocol ImprovManagerProtocol: ObservableObject {
func scan()
func stopScan()
func connectToDevice(_ peripheral: CBPeripheral)
func disconnectFromDevice(_ peripheral: CBPeripheral)
func identifyDevice()
func sendWifi(ssid: String, password: String)
func reset()
Expand Down Expand Up @@ -90,10 +91,13 @@ public final class ImprovManager: NSObject, ImprovManagerProtocol {
}

public func connectToDevice(_ peripheral: CBPeripheral) {
stopScan()
bluetoothManager.connectToDevice(peripheral)
}

public func disconnectFromDevice(_ peripheral: CBPeripheral) {
bluetoothManager.disconnectFromDevice(peripheral)
}

public func identifyDevice() {
bluetoothManager.identifyDevice()
}
Expand Down

0 comments on commit b7a993c

Please sign in to comment.