Skip to content

Commit

Permalink
Add method to reset information and clean up found devices when stop …
Browse files Browse the repository at this point in the history
…scanning
  • Loading branch information
bgoncal committed Jul 16, 2024
1 parent 64bd83e commit 44786ae
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 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.2"
spec.version = "0.0.3"
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>0</integer>
<integer>1</integer>
</dict>
<key>Improve-iOS-Demo.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>1</integer>
<integer>0</integer>
</dict>
</dict>
</dict>
Expand Down
17 changes: 17 additions & 0 deletions Improv-iOS/ImprovManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public protocol ImprovManagerProtocol: ObservableObject {
func connectToDevice(_ peripheral: CBPeripheral)
func identifyDevice()
func sendWifi(ssid: String, password: String)
func reset()
}

public protocol ImprovManagerDelegate: AnyObject {
Expand All @@ -34,6 +35,8 @@ public protocol ImprovManagerDelegate: AnyObject {
func didUpdateErrorState(_ state: ErrorState?)

func didReceiveResult(_ result: [String]?)

func didReset()
}

public final class ImprovManager: NSObject, ImprovManagerProtocol {
Expand Down Expand Up @@ -82,6 +85,8 @@ public final class ImprovManager: NSObject, ImprovManagerProtocol {
public func stopScan() {
bluetoothManager.stopScan()
scanInProgress = false
foundDevices = [:]
delegate?.didUpdateFoundDevices(devices: foundDevices)
}

public func connectToDevice(_ peripheral: CBPeripheral) {
Expand All @@ -96,6 +101,18 @@ public final class ImprovManager: NSObject, ImprovManagerProtocol {
public func sendWifi(ssid: String, password: String) {
bluetoothManager.sendWifi(ssid: ssid, password: password)
}

public func reset() {
stopScan()
bluetoothState = bluetoothManager.state
errorState = nil
deviceState = nil
lastResult = nil
foundDevices = [String: CBPeripheral]()
connectedDevice = nil

delegate?.didReset()
}
}

extension ImprovManager: BluetoothManagerDelegate {
Expand Down

0 comments on commit 44786ae

Please sign in to comment.