From 1b9ce5a1ba30691f7c4d404e6efd8c9ed02c230e Mon Sep 17 00:00:00 2001 From: Sagar Dagdu Date: Sun, 25 Aug 2024 10:07:18 +0530 Subject: [PATCH] Update README.md --- README.md | 41 +++++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index a3f39f2..bf8776e 100644 --- a/README.md +++ b/README.md @@ -99,13 +99,12 @@ To start scanning for beacons, you can use either of the following methods depen #### Scan by UUID ```swift -beaconScanner.getNearbyBeacons(uuid: "your-uuid") { beacons, error in - if let error = error { - // Handle error - print("Error scanning beacons: \(error)") - } else { - // Handle found beacons - print("Found beacons: \(beacons)") +beaconScanner.getNearbyBeacons(uuid: "your-uuid") { scanResult in + switch scanResult { + case let .success(beacons): + print("Got \(beacons.count) beacons") + case let .failure(scanError): + print("Error: \(scanError)") } } ``` @@ -113,13 +112,12 @@ beaconScanner.getNearbyBeacons(uuid: "your-uuid") { beacons, error in #### Scan by UUID, Major, and Minor ```swift -beaconScanner.getNearbyBeacons(uuid: "your-uuid", major: 123, minor: 456) { beacons, error in - if let error = error { - // Handle error - print("Error scanning beacons: \(error)") - } else { - // Handle found beacons - print("Found beacons: \(beacons)") +beaconScanner.getNearbyBeacons(uuid: "your-uuid", major: 123, minor: 456) { scanResult in + switch scanResult { + case let .success(beacons): + print("Got \(beacons.count) beacons") + case let .failure(scanError): + print("Error: \(scanError)") } } ``` @@ -129,11 +127,12 @@ beaconScanner.getNearbyBeacons(uuid: "your-uuid", major: 123, minor: 456) { beac You can specify a custom timeout duration (in seconds) for the scan. The scan will automatically stop once the timeout is reached or once beacons are found. ```swift -beaconScanner.getNearbyBeacons(uuid: "your-uuid", timeout: 10.0) { beacons, error in - if let error = error { - print("Error scanning beacons: \(error)") - } else { - print("Found beacons: \(beacons)") +beaconScanner.getNearbyBeacons(uuid: "your-uuid", timeout: 10.0) { scanResult in + switch scanResult { + case let .success(beacons): + print("Got \(beacons.count) beacons") + case let .failure(scanError): + print("Error: \(scanError)") } } ``` @@ -148,12 +147,11 @@ SDBeaconScanner provides detailed error handling through the `BeaconScannerError - `invalidUUID`: Indicates that the provided UUID is not valid. - `rangingUnavailable`: Indicates that the device does not support ranging. -- `rangingFailed(NSError)`: A generic error that reports an NSError object, typically triggered by internal location manager issues. +- `rangingFailed(NSError)`: A generic error that reports an `NSError` object, typically triggered by internal location manager issues. Example usage: ```swift -if let error = error as? BeaconScannerError { switch error { case .invalidUUID: print("The UUID provided is invalid.") @@ -162,7 +160,6 @@ if let error = error as? BeaconScannerError { case .rangingFailed(let nsError): print("Ranging failed with error: \(nsError.localizedDescription)") } -} ``` ## Example