Skip to content

Commit d0928d7

Browse files
committed
update
1 parent b388ac7 commit d0928d7

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,11 @@ extension LocationManagerAsync{
4646
// MARK: - API
4747

4848
/// Get status asynchronously and check is it authorized to start getting the stream of locations
49-
public func isGranted(for manager: CLLocationManager) async -> Bool{
49+
public func grant(for manager: CLLocationManager) async throws {
5050
let status = await requestPermission(manager)
51-
return isAuthorized(status)
51+
if !isAuthorized(status){
52+
throw AsyncLocationErrors.accessIsNotAuthorized
53+
}
5254
}
5355

5456
// MARK: - Private methods

Sources/d3-async-location/LocationManagerAsync.swift

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import CoreLocation
1212
final class LocationManagerAsync: ILocationManagerAsync{
1313

1414
// MARK: - Private properties
15-
15+
1616
/// Location manager
1717
private let manager = CLLocationManager()
1818

@@ -24,8 +24,8 @@ final class LocationManagerAsync: ILocationManagerAsync{
2424
/// Async stream of ``CLLocation``
2525
private var locations : AsyncThrowingStream<CLLocation, Error>{
2626
.init(CLLocation.self) { continuation in
27-
streaming(with: continuation)
28-
}
27+
streaming(with: continuation)
28+
}
2929
}
3030

3131
// MARK: - Life circle
@@ -42,22 +42,23 @@ final class LocationManagerAsync: ILocationManagerAsync{
4242

4343
updateSettings(accuracy, activityType, distanceFilter, backgroundUpdates)
4444
}
45-
46-
45+
46+
4747
// MARK: - API
4848

4949
/// Check status and get stream of async data Throw an error ``AsyncLocationErrors`` if permission is not granted
5050
public var start : AsyncThrowingStream<CLLocation, Error>{
5151
get async throws {
5252
let permission = Permission(with: manager.authorizationStatus)
5353

54-
if await permission.isGranted(for: manager){
55-
#if DEBUG
56-
print("start")
57-
#endif
58-
return locations
59-
}
60-
throw AsyncLocationErrors.accessIsNotAuthorized
54+
try await permission.grant(for: manager)
55+
56+
#if DEBUG
57+
print("start")
58+
#endif
59+
60+
return locations
61+
6162
}
6263
}
6364

@@ -72,7 +73,7 @@ final class LocationManagerAsync: ILocationManagerAsync{
7273
}
7374

7475
// MARK: - Private
75-
76+
7677
// Streaming locations
7778

7879
/// Start updating
@@ -101,5 +102,3 @@ final class LocationManagerAsync: ILocationManagerAsync{
101102
manager.allowsBackgroundLocationUpdates = backgroundUpdates
102103
}
103104
}
104-
105-

0 commit comments

Comments
 (0)