Settings: test alert notification button

Fires a local notification shaped exactly like a real price alert (uses the
currently configured alerts fuel + radius), with permission-gated handling:
prompts on first use, guides to Settings when denied. Tapping it opens
FuelBoard, same as a real alert.
This commit is contained in:
FuelBoard Contributor
2026-08-12 09:15:04 +01:00
parent 3dcfe30dcc
commit d6550409df
3 changed files with 68 additions and 1 deletions
+15
View File
@@ -172,4 +172,19 @@ final class ProximityMonitor: NSObject, ObservableObject, @preconcurrency CLLoca
lastAlert = "\(brand) · \(String(format: "%.1fp", price)) · \(unit.format(radiusKM)) radius"
}
/// Fires a sample local notification shaped exactly like a real price
/// alert, for the Settings "test" button. Uses a placeholder station so
/// the user can see the alert format without a real entry event. Tapping
/// it does what tapping any FuelBoard alert does opens the app.
static func sendTestNotification(fuel: FuelType, radiusKM: Double) {
let unit = FuelStore.loadDistanceUnit()
let content = UNMutableNotificationContent()
content.title = "Cheapest \(fuel.displayName) nearby: Sample Filling Station"
content.body = "Sample Filling Station is the cheapest within \(unit.format(radiusKM)) at 132.9p. Tap to open."
content.sound = .default
let request = UNNotificationRequest(identifier: UUID().uuidString, content: content, trigger: nil)
UNUserNotificationCenter.current().add(request)
}
}