Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions OpenGpxTracker-Watch Extension/InterfaceController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -331,16 +331,25 @@ class InterfaceController: WKInterfaceController {
/// - Seealso: displayLocationServicesDisabledAlert, displayLocationServicesDeniedAlert
///
func checkLocationServicesStatus() {
//Are location services enabled?
if !CLLocationManager.locationServicesEnabled() {
displayLocationServicesDisabledAlert()
let authorizationStatus = CLLocationManager.authorizationStatus()

//Has the user already made a permission choice?
guard authorizationStatus != .notDetermined else {
//We should take no action until the user has made a choice
return
}

//Does the app have permissions to use the location servies?
if !([.authorizedAlways, .authorizedWhenInUse].contains(CLLocationManager.authorizationStatus())) {
guard [.authorizedAlways, .authorizedWhenInUse ].contains(authorizationStatus) else {
displayLocationServicesDeniedAlert()
return
}

//Are location services enabled?
guard CLLocationManager.locationServicesEnabled() else {
displayLocationServicesDisabledAlert()
return
}
}

///
Expand Down
30 changes: 23 additions & 7 deletions OpenGpxTracker/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,6 @@ class ViewController: UIViewController, UIGestureRecognizerDelegate {
if !wasSentToBackground {
return
}
checkLocationServicesStatus()
locationManager.startUpdatingLocation()
locationManager.startUpdatingHeading()
}
Expand Down Expand Up @@ -1170,16 +1169,26 @@ class ViewController: UIViewController, UIGestureRecognizerDelegate {
/// - Seealso: displayLocationServicesDisabledAlert, displayLocationServicesDeniedAlert
///
func checkLocationServicesStatus() {
//Are location services enabled?
if !CLLocationManager.locationServicesEnabled() {
displayLocationServicesDisabledAlert()
let authorizationStatus = CLLocationManager.authorizationStatus()

//Has the user already made a permission choice?
guard authorizationStatus != .notDetermined else {
//We should take no action until the user has made a choice
//Note that we request location permission as part of the property `locationManager` init
return
}

//Does the app have permissions to use the location servies?
if !([.authorizedAlways, .authorizedWhenInUse].contains(CLLocationManager.authorizationStatus())) {
guard [.authorizedAlways, .authorizedWhenInUse ].contains(authorizationStatus) else {
displayLocationServicesDeniedAlert()
return
}

//Are location services enabled?
guard CLLocationManager.locationServicesEnabled() else {
displayLocationServicesDisabledAlert()
return
}
}
///
/// Displays an alert that informs the user that location services are disabled.
Expand Down Expand Up @@ -1294,8 +1303,6 @@ extension ViewController: PreferencesTableViewControllerDelegate {
signalAccuracyLabel.text = kUnknownAccuracyText
}}

// MARK: location manager Delegate

/// Extends `ViewController`` to support `GPXFilesTableViewControllerDelegate` function
/// that loads into the map a the file selected by the user.
extension ViewController: GPXFilesTableViewControllerDelegate {
Expand Down Expand Up @@ -1418,6 +1425,15 @@ extension ViewController: CLLocationManagerDelegate {
map.updateHeading() // updates heading view's rotation

}

///
/// Called by the system when `CLLocationManager` is created and when the user makes a permission choice
///
/// We handle this delegate callback so that we can check if the user has allowed location access, else we show a warning
///
func locationManagerDidChangeAuthorization(_ manager: CLLocationManager) {
checkLocationServicesStatus()
}
}

extension Notification.Name {
Expand Down