Skip to content

Commit 05bc269

Browse files
committed
Update Permission.swift
1 parent d0928d7 commit 05bc269

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

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

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ extension LocationManagerAsync{
4848
/// Get status asynchronously and check is it authorized to start getting the stream of locations
4949
public func grant(for manager: CLLocationManager) async throws {
5050
let status = await requestPermission(manager)
51-
if !isAuthorized(status){
51+
if status.isNotAuthorized{
5252
throw AsyncLocationErrors.accessIsNotAuthorized
5353
}
5454
}
@@ -74,13 +74,6 @@ extension LocationManagerAsync{
7474
}
7575
}
7676

77-
/// Check permission status
78-
/// - Parameter status: Constant indicating the app's authorization to use location services
79-
/// - Returns: Return `True` if is allowed
80-
private func isAuthorized(_ status : CLAuthorizationStatus) -> Bool{
81-
[CLAuthorizationStatus.authorizedWhenInUse, .authorizedAlways].contains(status)
82-
}
83-
8477
/// Requests the user’s permission to use location services while the app is in use
8578
/// Don't forget to add in Info "Privacy - Location When In Use Usage Description" something like "Show list of locations"
8679
/// - Returns: Permission status
@@ -96,9 +89,20 @@ extension LocationManagerAsync{
9689
}
9790
}
9891
}
99-
100-
// MARK: - Alias types -
92+
}
10193

102-
fileprivate typealias Output = NotificationCenter.Publisher.Output
103-
94+
// MARK: - Alias types -
95+
96+
fileprivate typealias Output = NotificationCenter.Publisher.Output
97+
98+
// MARK: - Extensions -
99+
100+
fileprivate extension CLAuthorizationStatus {
101+
/// Check if access is not authorized
102+
/// denied - The user denied the use of location services for the app or they are disabled globally in Settings
103+
/// restricted - The app is not authorized to use location services
104+
/// - Returns: Return `True` if it was denied
105+
var isNotAuthorized: Bool {
106+
[.denied, .restricted].contains(self)
107+
}
104108
}

0 commit comments

Comments
 (0)