Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
SagarSDagdu committed Aug 25, 2024
1 parent 6880254 commit 1b9ce5a
Showing 1 changed file with 19 additions and 22 deletions.
41 changes: 19 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,27 +99,25 @@ 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)")
}
}
```

#### 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)")
}
}
```
Expand All @@ -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)")
}
}
```
Expand All @@ -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.")
Expand All @@ -162,7 +160,6 @@ if let error = error as? BeaconScannerError {
case .rangingFailed(let nsError):
print("Ranging failed with error: \(nsError.localizedDescription)")
}
}
```

## Example
Expand Down

0 comments on commit 1b9ce5a

Please sign in to comment.