Wetter: fehlende Ortungserlaubnis wird als solche benannt
"Wetter nicht abrufbar" war eine falsche Auskunft: abrufbar war es sehr wohl, es fehlte nur die Erlaubnis. Derselbe Fehlertyp wie zuvor beim Kalender — ein Zustand, den die App nicht kennt, landet im nächstbesten Sammelfall und schickt den Nutzer damit in die Irre. locationUndetermined ist jetzt ein eigener Zustand neben locationDenied. Der Unterschied ist nicht kosmetisch: bei undetermined lohnt eine Anfrage, bei denied fragt macOS nie wieder und es hilft nur der Weg über die Systemeinstellungen oder ein fest gewählter Ort. Beide Fälle führen jetzt dorthin, wo es weitergeht. Die Anfrage kommt aus dem Berechtigungen-Reiter, nicht aus dem Hintergrund — dieselbe Lehre wie beim Kalender: ohne Vordergrundfenster zeigt macOS keinen Dialog, und die App wirkt kaputt, ohne dass irgendwo ein Fehler steht. Aufgefallen war es daran, dass im Protokoll überhaupt kein Wetter-Eintrag stand. Der einzige Pfad zu "nicht abrufbar" ohne Protokolleintrag war der Standort — jetzt protokolliert auch der.
This commit is contained in:
@@ -1,31 +1,95 @@
|
||||
{
|
||||
"sourceLanguage" : "en",
|
||||
"strings" : {
|
||||
"widget.weather.name" : {
|
||||
"localizations" : {
|
||||
"de" : { "stringUnit" : { "state" : "translated", "value" : "Wetter" } },
|
||||
"en" : { "stringUnit" : { "state" : "translated", "value" : "Weather" } }
|
||||
"sourceLanguage": "en",
|
||||
"strings": {
|
||||
"↑ %@": {
|
||||
"comment": "A label that shows the high temperature. The argument is the high temperature.",
|
||||
"isCommentAutoGenerated": true
|
||||
},
|
||||
"↓ %@": {
|
||||
"comment": "A label that reads \"low\" in the weather app.",
|
||||
"isCommentAutoGenerated": true
|
||||
},
|
||||
"widget.weather.asOf": {
|
||||
"comment": "%@ ist die Uhrzeit des Messwerts",
|
||||
"localizations": {
|
||||
"de": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Stand %@"
|
||||
}
|
||||
},
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "As of %@"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"widget.weather.asOf" : {
|
||||
"comment" : "%@ ist die Uhrzeit des Messwerts",
|
||||
"localizations" : {
|
||||
"de" : { "stringUnit" : { "state" : "translated", "value" : "Stand %@" } },
|
||||
"en" : { "stringUnit" : { "state" : "translated", "value" : "As of %@" } }
|
||||
"widget.weather.locationDenied": {
|
||||
"localizations": {
|
||||
"de": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Kein Standortzugriff.\nOrt in den Einstellungen wählen."
|
||||
}
|
||||
},
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "No location access.\nPick a place in settings."
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"widget.weather.unavailable" : {
|
||||
"localizations" : {
|
||||
"de" : { "stringUnit" : { "state" : "translated", "value" : "Wetter nicht abrufbar" } },
|
||||
"en" : { "stringUnit" : { "state" : "translated", "value" : "Weather unavailable" } }
|
||||
"widget.weather.name": {
|
||||
"localizations": {
|
||||
"de": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Wetter"
|
||||
}
|
||||
},
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Weather"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"widget.weather.locationDenied" : {
|
||||
"localizations" : {
|
||||
"de" : { "stringUnit" : { "state" : "translated", "value" : "Kein Standortzugriff.\nOrt in den Einstellungen wählen." } },
|
||||
"en" : { "stringUnit" : { "state" : "translated", "value" : "No location access.\nPick a place in settings." } }
|
||||
"widget.weather.unavailable": {
|
||||
"localizations": {
|
||||
"de": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Wetter nicht abrufbar"
|
||||
}
|
||||
},
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Weather unavailable"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"widget.weather.locationUndetermined": {
|
||||
"localizations": {
|
||||
"de": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Standort noch nicht erlaubt.\nIn den Einstellungen freigeben."
|
||||
}
|
||||
},
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Location not allowed yet.\nGrant it in settings."
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"version" : "1.0"
|
||||
}
|
||||
"version": "1.1"
|
||||
}
|
||||
@@ -28,6 +28,8 @@ final class LocationProvider: NSObject, CLLocationManagerDelegate {
|
||||
authorization == .denied || authorization == .restricted
|
||||
}
|
||||
|
||||
var isUndetermined: Bool { authorization == .notDetermined }
|
||||
|
||||
func requestAuthorization() {
|
||||
guard authorization == .notDetermined else { return }
|
||||
manager.requestWhenInUseAuthorization()
|
||||
@@ -36,13 +38,7 @@ final class LocationProvider: NSObject, CLLocationManagerDelegate {
|
||||
/// Eine einzelne Ortung. Liefert `nil`, wenn keine Berechtigung vorliegt
|
||||
/// oder nichts hereinkommt.
|
||||
func currentLocation() async -> CLLocation? {
|
||||
guard !isDenied else { return nil }
|
||||
if authorization == .notDetermined {
|
||||
requestAuthorization()
|
||||
// Auf die Entscheidung des Nutzers warten hieße, hier zu blockieren.
|
||||
// Beim nächsten Durchlauf steht sie fest.
|
||||
return nil
|
||||
}
|
||||
guard !isDenied, !isUndetermined else { return nil }
|
||||
if let cached = manager.location, cached.timestamp.timeIntervalSinceNow > -900 {
|
||||
return cached
|
||||
}
|
||||
@@ -83,6 +79,13 @@ public final class WeatherKitSource {
|
||||
public init() {}
|
||||
|
||||
public var locationIsDenied: Bool { location.isDenied }
|
||||
public var locationIsUndetermined: Bool { location.isUndetermined }
|
||||
public var locationIsAuthorized: Bool { !location.isDenied && !location.isUndetermined }
|
||||
|
||||
/// Fragt die Ortungsberechtigung an.
|
||||
///
|
||||
/// Muss aus einem Vordergrundfenster gerufen werden — wie beim Kalender
|
||||
/// zeigt macOS den Dialog sonst nicht an, und die App wirkt kaputt.
|
||||
public func requestLocationAuthorization() { location.requestAuthorization() }
|
||||
|
||||
public func load(_ place: WeatherPlace) async -> WeatherState {
|
||||
@@ -91,8 +94,14 @@ public final class WeatherKitSource {
|
||||
|
||||
switch place {
|
||||
case .current:
|
||||
if location.isUndetermined {
|
||||
log.notice("Wetter: Ortungsberechtigung noch nicht erteilt")
|
||||
return .locationUndetermined
|
||||
}
|
||||
guard let here = await location.currentLocation() else {
|
||||
return location.isDenied
|
||||
let denied = location.isDenied
|
||||
log.error("Wetter: keine Ortung erhalten (verweigert: \(denied, privacy: .public))")
|
||||
return denied
|
||||
? .locationDenied
|
||||
: .unavailable(lastKnown: nil, reason: "Standort nicht verfügbar")
|
||||
}
|
||||
|
||||
@@ -118,8 +118,16 @@ public enum WeatherState: Equatable, Sendable {
|
||||
/// Noch nie geladen.
|
||||
case idle
|
||||
case loading
|
||||
/// Ortungsberechtigung fehlt — betrifft nur `.current`.
|
||||
/// Ortungsberechtigung wurde verweigert — betrifft nur `.current`.
|
||||
/// macOS fragt dann nicht mehr; es hilft nur der Weg über die
|
||||
/// Systemeinstellungen oder ein fest gewählter Ort.
|
||||
case locationDenied
|
||||
/// Es wurde noch nie gefragt. Anders als `denied` lohnt hier eine Anfrage —
|
||||
/// und sie muss aus einem Vordergrundfenster kommen, sonst zeigt macOS
|
||||
/// keinen Dialog. Ein eigener Zustand, weil "nicht abrufbar" hier eine
|
||||
/// falsche Auskunft wäre: abrufbar ist es sehr wohl, es fehlt nur die
|
||||
/// Erlaubnis.
|
||||
case locationUndetermined
|
||||
/// Kein Netz oder Dienst nicht erreichbar. Der letzte Stand bleibt sichtbar.
|
||||
case unavailable(lastKnown: WeatherSnapshot?, reason: String)
|
||||
}
|
||||
|
||||
@@ -23,7 +23,20 @@ public final class WeatherModel {
|
||||
}
|
||||
|
||||
public var locationIsDenied: Bool { source.locationIsDenied }
|
||||
public func requestLocationAuthorization() { source.requestLocationAuthorization() }
|
||||
public var locationIsUndetermined: Bool { source.locationIsUndetermined }
|
||||
public var locationIsAuthorized: Bool { source.locationIsAuthorized }
|
||||
|
||||
/// Fragt die Ortungsberechtigung an und lädt danach.
|
||||
public func requestLocationAuthorization() {
|
||||
source.requestLocationAuthorization()
|
||||
// Die Entscheidung fällt asynchron. Kurz warten und dann laden — die
|
||||
// Alternative wäre ein Delegat quer durch drei Schichten für einen
|
||||
// Vorgang, der einmal im Leben der App passiert.
|
||||
Task { [weak self] in
|
||||
try? await Task.sleep(for: .seconds(2))
|
||||
self?.load(force: true)
|
||||
}
|
||||
}
|
||||
|
||||
/// Lädt, wenn der Zwischenspeicher abgelaufen ist.
|
||||
///
|
||||
@@ -99,6 +112,8 @@ private struct WeatherWidgetView: View {
|
||||
}
|
||||
case .locationDenied:
|
||||
Notice(symbol: "location.slash", text: "widget.weather.locationDenied")
|
||||
case .locationUndetermined:
|
||||
Notice(symbol: "location.circle", text: "widget.weather.locationUndetermined")
|
||||
case .loading, .idle:
|
||||
ProgressView()
|
||||
.controlSize(.small)
|
||||
|
||||
Reference in New Issue
Block a user