Skip to content

Commit d3de92d

Browse files
committed
update
1 parent e238d40 commit d3de92d

File tree

4 files changed

+24
-4
lines changed

4 files changed

+24
-4
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
- [x] Customizable in terms of CLLocationManager properties
77
- [x] Streaming current locations asynchronously
88
- [x] Support for iOS and watchOS
9-
- [x] Errors handling
9+
- [x] Errors handling (as custom so CoreLocation errors)
1010

1111
## How to use
1212

@@ -52,6 +52,9 @@ If task will be canceled the streaming stops automatically. I would recomend to
5252
5353
/// Stream was cancelled or terminated
5454
case streamTerminated
55+
56+
/// A Core Location error
57+
case coreLocationManagerError(CLError)
5558
```
5659

5760
### LMViewModel API
@@ -85,6 +88,7 @@ public protocol ILocationManagerViewModel: ObservableObject{
8588
3. Option tab
8689
4. Already checked Core Location > select your location
8790
5. Press OK
91+
8892
![Default location](https://github.com/The-Igor/d3-async-location/blob/main/img/image6.png)
8993

9094
## SwiftUI example of using package

Sources/d3-async-location/LocationManagerAsync+/Delegate.swift

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,21 @@ extension LocationManagerAsync{
4040
NotificationCenter.default.post(name: Permission.authorizationStatus, object: manager.authorizationStatus)
4141
}
4242

43+
44+
/// Tells the delegate that the location manager was unable to retrieve a location value
45+
/// - Parameters:
46+
/// - manager: The location manager object that was unable to retrieve the location
47+
/// - error: The error object containing the reason the location or heading could not be retrieved
4348
func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
44-
print(error)
49+
guard let e = error as? CLError else{ return }
50+
51+
if e.code == CLError.locationUnknown{
52+
return /// glitch throwing this error on some devices and simulator while changing locations time by time
53+
}
54+
55+
let type = AsyncLocationErrors.self
56+
stream?.finish(throwing: type.coreLocationManagerError(e))
57+
4558
}
4659

4760
// MARK: - Private

Sources/d3-async-location/LocationManagerAsync.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ final class LocationManagerAsync: ILocationManagerAsync{
1616
/// Location manager
1717
private let manager = CLLocationManager()
1818

19-
/// Delegate adapter
19+
/// Delegate
2020
private let delegate = Delegate()
2121

2222
// Streaming locations

Sources/d3-async-location/enum/AsyncLocationErrors.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// Created by Igor on 03.02.2023.
66
//
77

8-
import Foundation
8+
import CoreLocation
99

1010
/// Async locations manager errors
1111
@available(iOS 15.0, watchOS 7.0, *)
@@ -21,4 +21,7 @@ public enum AsyncLocationErrors: Error{
2121
/// Stream was cancelled or terminated
2222
case streamTerminated
2323

24+
/// A Core Location error
25+
case coreLocationManagerError(CLError)
26+
2427
}

0 commit comments

Comments
 (0)