From f679c7d357a6290606d04cc2b6fa7db3e7d2f4a4 Mon Sep 17 00:00:00 2001 From: fmodf Date: Thu, 4 Jul 2024 13:54:09 +0200 Subject: [PATCH] wip --- .../Helpers/UIApplication+Extensions.swift | 10 +++++++++ .../AttachmentLocationPickerView.swift | 21 +++++++++++++++++++ .../AttachmentMediaPickerView.swift | 9 -------- 3 files changed, 31 insertions(+), 9 deletions(-) create mode 100644 ConversationsClassic/Helpers/UIApplication+Extensions.swift diff --git a/ConversationsClassic/Helpers/UIApplication+Extensions.swift b/ConversationsClassic/Helpers/UIApplication+Extensions.swift new file mode 100644 index 0000000..63550f5 --- /dev/null +++ b/ConversationsClassic/Helpers/UIApplication+Extensions.swift @@ -0,0 +1,10 @@ +import UIKit + +func openAppSettings() { + if + let appSettingsUrl = URL(string: UIApplication.openSettingsURLString), + UIApplication.shared.canOpenURL(appSettingsUrl) + { + UIApplication.shared.open(appSettingsUrl, completionHandler: nil) + } +} diff --git a/ConversationsClassic/View/Screens/Attachments/AttachmentLocationPickerView.swift b/ConversationsClassic/View/Screens/Attachments/AttachmentLocationPickerView.swift index c82c05f..29addfc 100644 --- a/ConversationsClassic/View/Screens/Attachments/AttachmentLocationPickerView.swift +++ b/ConversationsClassic/View/Screens/Attachments/AttachmentLocationPickerView.swift @@ -9,6 +9,7 @@ struct AttachmentLocationPickerView: View { center: CLLocationCoordinate2D(latitude: 34.011_286, longitude: -116.166_868), span: MKCoordinateSpan(latitudeDelta: 0.2, longitudeDelta: 0.2) ) + @State private var showingAlert = false var body: some View { MapView(coordinateRegion: $region) @@ -20,14 +21,30 @@ struct AttachmentLocationPickerView: View { region.center = newLocation.coordinate } } + .onChange(of: locationManager.authorizationStatus) { newStatus in + if newStatus == .denied { + showingAlert = true + } + } + .alert(isPresented: $showingAlert) { + Alert( + title: Text("Location Permission Denied"), + message: Text("Please enable location permissions in settings."), + dismissButton: .default(Text("OK")) { + openAppSettings() + } + ) + } } } class LocationManager: NSObject, ObservableObject, CLLocationManagerDelegate { private let locationManager = CLLocationManager() @Published var lastLocation: CLLocation? + @Published var authorizationStatus: CLAuthorizationStatus override init() { + authorizationStatus = locationManager.authorizationStatus super.init() locationManager.delegate = self } @@ -40,6 +57,10 @@ class LocationManager: NSObject, ObservableObject, CLLocationManagerDelegate { func locationManager(_: CLLocationManager, didUpdateLocations locations: [CLLocation]) { lastLocation = locations.first } + + func locationManager(_: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) { + authorizationStatus = status + } } struct MapView: UIViewRepresentable { diff --git a/ConversationsClassic/View/Screens/Attachments/AttachmentMediaPickerView.swift b/ConversationsClassic/View/Screens/Attachments/AttachmentMediaPickerView.swift index 7c8a34b..48bf788 100644 --- a/ConversationsClassic/View/Screens/Attachments/AttachmentMediaPickerView.swift +++ b/ConversationsClassic/View/Screens/Attachments/AttachmentMediaPickerView.swift @@ -229,15 +229,6 @@ struct AttachmentMediaPickerView: View { } } } - - func openAppSettings() { - if - let appSettingsUrl = URL(string: UIApplication.openSettingsURLString), - UIApplication.shared.canOpenURL(appSettingsUrl) - { - UIApplication.shared.open(appSettingsUrl, completionHandler: nil) - } - } } private struct ThumbnailView: Identifiable, View {