Fix location/weather error handling and complete localization
Add authorization pre-check and 15s timeout to LocationManager to prevent hanging continuations. WeatherManager now skips retry queue when location permission is denied. Settings weather toggle shows alert directing users to Settings when location is denied. Fill remaining 32 untranslated strings to reach 100% localization. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -42,9 +42,49 @@ final class LocationManager: NSObject {
|
||||
return last
|
||||
}
|
||||
|
||||
// Pre-check authorization before requesting location
|
||||
switch manager.authorizationStatus {
|
||||
case .denied, .restricted:
|
||||
throw LocationError.permissionDenied
|
||||
case .notDetermined:
|
||||
manager.requestWhenInUseAuthorization()
|
||||
// Wait briefly for authorization response
|
||||
try await Task.sleep(for: .seconds(1))
|
||||
if manager.authorizationStatus == .denied || manager.authorizationStatus == .restricted {
|
||||
throw LocationError.permissionDenied
|
||||
}
|
||||
default:
|
||||
break
|
||||
}
|
||||
|
||||
// Request location with a 15-second timeout
|
||||
return try await withCheckedThrowingContinuation { continuation in
|
||||
self.locationContinuation = continuation
|
||||
self.manager.requestLocation()
|
||||
|
||||
// Schedule timeout — safe because everything is @MainActor (no race)
|
||||
Task { @MainActor in
|
||||
try? await Task.sleep(for: .seconds(15))
|
||||
guard self.locationContinuation != nil else { return }
|
||||
self.locationContinuation?.resume(throwing: LocationError.timeout)
|
||||
self.locationContinuation = nil
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Errors
|
||||
|
||||
enum LocationError: LocalizedError {
|
||||
case permissionDenied
|
||||
case timeout
|
||||
|
||||
var errorDescription: String? {
|
||||
switch self {
|
||||
case .permissionDenied:
|
||||
return "Location permission denied"
|
||||
case .timeout:
|
||||
return "Location request timed out"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user