Skip to content

Commit

Permalink
General maintenance on Permissions.swift (#2607)
Browse files Browse the repository at this point in the history
<!-- Thank you for submitting a Pull Request and helping to improve Home
Assistant. Please complete the following sections to help the processing
and review of your changes. Please do not delete anything from this
template. -->

## Summary
<!-- Provide a brief summary of the changes you have made and most
importantly what they aim to achieve -->

## Screenshots
<!-- If this is a user-facing change not in the frontend, please include
screenshots in light and dark mode. -->
<img width="1054" alt="Screenshot 2024-02-26 at 18 20 11"
src="https://github.com/home-assistant/iOS/assets/5808343/3ad33795-8709-4a0c-b6a5-aa6cd5b4d831">
<img width="1054" alt="Screenshot 2024-02-26 at 18 21 47"
src="https://github.com/home-assistant/iOS/assets/5808343/0ceaa35b-ec2e-4643-a16d-2d08ba83ef52">

## Link to pull request in Documentation repository
<!-- Pull requests that add, change or remove functionality must have a
corresponding pull request in the Companion App Documentation repository
(https://github.com/home-assistant/companion.home-assistant). Please add
the number of this pull request after the "#" -->
Documentation: home-assistant/companion.home-assistant#

## Any other notes
<!-- If there is any other information of note, like if this Pull
Request is part of a bigger change, please include it here. -->
  • Loading branch information
bgoncal authored Mar 3, 2024
1 parent 5e777be commit 3607147
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions Sources/App/Utilities/Permissions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,11 @@ public enum PermissionType {
}

var status: PermissionStatus {
let locationManager = CLLocationManager()
switch self {
case .location:
guard CLLocationManager.locationServicesEnabled() else { return .restricted }
return CLLocationManager.authorizationStatus().genericStatus
return locationManager.authorizationStatus.genericStatus
case .motion:
return CMMotionActivityManager.authorizationStatus().genericStatus
case .notification:
Expand Down Expand Up @@ -290,13 +291,6 @@ public extension UNAuthorizationOptions {
opts.insert(.criticalAlert)
}

opts.insert(.announcement)

if #available(iOS 15, *) {
// this is also deprecated in iOS 15 in favor of the entitlement, but it does seem to be required in b1
opts.insert(.timeSensitive)
}

return opts
}
}
Expand Down Expand Up @@ -332,7 +326,7 @@ private class PermissionsLocationDelegate: NSObject, CLLocationManagerDelegate {
func requestPermission(_ completionHandler: @escaping LocationPermissionCompletionBlock) {
self.completionHandler = completionHandler

let status = CLLocationManager.authorizationStatus()
let status = locationManager.authorizationStatus

switch status {
case .authorizedWhenInUse, .notDetermined:
Expand All @@ -344,7 +338,7 @@ private class PermissionsLocationDelegate: NSObject, CLLocationManagerDelegate {
}

var isAuthorized: Bool {
switch CLLocationManager.authorizationStatus() {
switch locationManager.authorizationStatus {
case .authorizedAlways, .authorizedWhenInUse:
return true
case .denied, .notDetermined, .restricted:
Expand Down

0 comments on commit 3607147

Please sign in to comment.