krz/moonrise

Night-sky companion for iPhone, Apple Watch and Vision Pro: what's up tonight, the Moon, planets, launches and missions, and a Library of the solar system. SwiftUI app with a Cloudflare Workers backend. astronomy cloudflare-workers ios night-sky space swiftui visionos watchos

Commit 1ee3c935aa

1ee3c935aacf6a3be0b957c6f7a38443f6e19915

parent: 21d86238a3

Unsigned

cmc <hello@cleberg.net> · 2026-10-22 01:58 UTC

ISS pass alerts: 15 minutes before each visible pass (!109)

Stacked on !108 (branch `widgets-controls`); merge !106–!108 first.

- Settings → "ISS passes" toggle (`issPassAlerts`, off by default) with its own permission message.
- `ISSPassNotifications`: up to 8 local notifications (`iss-pass-0…7`), 15 min before each visible ISS pass in `SkyModel.passes` (next 72 h). Body: rise time and direction, highest altitude and time, set time and direction.
- Rescheduled with the daily summary: Settings dismissed, place change, app active (`rescheduleSummary` → `rescheduleNotifications`).
- Nothing leaves the device. iOS builds. Not run on a device: notification permission needs a tap.

Layout: unified · split

App/Sources/ISSPassNotifications.swift added +37
@@ -0,0 +1,37 @@
1import SkyEngine
2import SwiftUI
3import UserNotifications
4
5/// Opt-in local notifications 15 minutes before each visible ISS pass in the next three days. Worked out on the
6/// device and replaced whenever the daily summary is.
7enum ISSPassNotifications {
8 static let ids = (0..<8).map { "iss-pass-\($0)" }
9 static let lead: TimeInterval = 15 * 60
10
11 @MainActor
12 static func reschedule(_ model: SkyModel) async {
13 let center = UNUserNotificationCenter.current()
14 center.removePendingNotificationRequests(withIdentifiers: ids)
15 guard UserDefaults.standard.bool(forKey: SettingsKey.issPasses) else { return }
16 await model.refreshPasses()
17 for (id, pass) in zip(ids, plan(model.passes)) {
18 let content = UNMutableNotificationContent()
19 content.title = "ISS pass in 15 minutes"
20 content.body = body(pass)
21 content.sound = .default
22 let trigger = UNTimeIntervalNotificationTrigger(timeInterval: pass.rise.timeIntervalSinceNow - lead, repeats: false)
23 try? await center.add(UNNotificationRequest(identifier: id, content: content, trigger: trigger))
24 }
25 }
26
27 /// Visible ISS passes whose alert time is still ahead, soonest first.
28 nonisolated static func plan(_ passes: [SatellitePass], now: Date = .now) -> [SatellitePass] {
29 passes.filter { $0.displayName == "ISS" && $0.visible && $0.rise.addingTimeInterval(-lead) > now }
30 .sorted { $0.rise < $1.rise }
31 }
32
33 nonisolated static func body(_ p: SatellitePass) -> String {
34 let t = { (d: Date) in d.formatted(date: .omitted, time: .shortened) }
35 return "Rises \(t(p.rise)) in the \(SkyEngine.compass(p.riseAzimuth)), highest \(Int(p.maxAltitude.rounded()))° at \(t(p.peak)), sets \(t(p.set)) in the \(SkyEngine.compass(p.setAzimuth))."
36 }
37}
App/Sources/SettingsScreen.swift +27
@@ -15,6 +15,8 @@ enum SettingsKey {
1515 /// Whether the Sky tab is currently drawn in night mode (written by the Sky tab).
1616 static let nightActive = "nightActive"
1717 static let dailySummary = "dailySummary"
18 /// Local alerts 15 minutes before visible ISS passes.
19 static let issPasses = "issPassAlerts"
1820 /// Sky culture id, or "western" for the IAU constellations.
1921 static let skyCulture = "skyCulture"
2022 /// Minutes after local midnight.
@@ -77,8 +79,10 @@ struct SettingsScreen: View {
7779 @Environment(\.dismiss) private var dismiss
7880 @State private var alerts = AuroraAlerts.shared
7981 @AppStorage(SettingsKey.dailySummary) private var dailySummary = false
82 @AppStorage(SettingsKey.issPasses) private var issPasses = false
8083 @AppStorage(SettingsKey.dailySummaryMinutes) private var dailySummaryMinutes = DailySummaryNotifications.defaultMinutes
8184 @State private var summaryStatus: String?
85 @State private var issStatus: String?
8286 @AppStorage(SettingsKey.cloudForecast) private var cloudForecast = false
8387 var onChange: () -> Void
8488
@@ -130,6 +134,17 @@ struct SettingsScreen: View {
130134 } footer: {
131135 Text("A note each day with the Moon, the planets up that night, the best satellite pass and any events. It is worked out on this device; nothing is sent to our server.")
132136 }
137 Section {
138 Toggle("ISS passes", isOn: Binding(
139 get: { issPasses },
140 set: { on in Task { await setISSPasses(on) } }
141 ))
142 if let issStatus {
143 Text(issStatus).font(.footnote).foregroundStyle(.secondary)
144 }
145 } footer: {
146 Text("An alert 15 minutes before the International Space Station crosses your sky while you can see it. Worked out on this device; nothing is sent to our server.")
147 }
133148 Section {
134149 Toggle("Cloud forecasts", isOn: $cloudForecast)
135150 } footer: {
@@ -192,6 +207,18 @@ struct SettingsScreen: View {
192207 )
193208 }
194209
210 private func setISSPasses(_ on: Bool) async {
211 if on {
212 let granted = (try? await UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound])) ?? false
213 guard granted else {
214 issStatus = "Notifications are off for Moonrise. Turn them on in the Settings app."
215 return
216 }
217 }
218 issStatus = nil
219 issPasses = on
220 }
221
195222 private func setDailySummary(_ on: Bool) async {
196223 if on {
197224 let granted = (try? await UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound])) ?? false
App/Sources/SkyScreen.swift +9 −5
@@ -104,7 +104,7 @@ struct SkyScreen: View {
104104 .sheet(isPresented: $showYear) {
105105 YearSheet(year: $model.historicalYear, south: model.observer.latitude < 0).preferredColorScheme(.dark)
106106 }
107 .sheet(isPresented: $showSettings, onDismiss: rescheduleSummary) {
107 .sheet(isPresented: $showSettings, onDismiss: rescheduleNotifications) {
108108 SettingsScreen { model.applyLocationSettings() }
109109 .preferredColorScheme(.dark)
110110 .tint(.blue)
@@ -122,8 +122,8 @@ struct SkyScreen: View {
122122 .onChange(of: model.scene == nil) { showRequestedTarget() }
123123 .onChange(of: onboarded) { if onboarded { model.start() } }
124124 .onChange(of: night, initial: true) { nightActive = night }
125 .onChange(of: model.observer) { rescheduleSummary() }
126 .onChange(of: scenePhase) { if scenePhase == .active { rescheduleSummary() } }
125 .onChange(of: model.observer) { rescheduleNotifications() }
126 .onChange(of: scenePhase) { if scenePhase == .active { rescheduleNotifications() } }
127127 .task {
128128 if onboarded { model.start() }
129129 while !Task.isCancelled {
@@ -190,8 +190,12 @@ struct SkyScreen: View {
190190 aim(at: t)
191191 }
192192
193 private func rescheduleSummary() {
194 Task { await DailySummaryNotifications.reschedule(model) }
193 /// The daily summary and ISS pass alerts.
194 private func rescheduleNotifications() {
195 Task {
196 await DailySummaryNotifications.reschedule(model)
197 await ISSPassNotifications.reschedule(model)
198 }
195199 }
196200
197201 private func select(_ object: SkyObject?) {
PLAN.org +10 −4
@@ -485,12 +485,18 @@ Sky, System, Sun, Launches, Library core (above).
485485 3D, checked on a device. Done: Sun snapshot OVATION grid zlib-compressed
486486 (grid 87 KB to 9 KB base64; snapshot 156 KB to about 78 KB).
487487
488** v4.2: widgets and controls
488** v4.2: provider usage terms
489Done: User-Agent with version and contact for every provider; LL2 429
490backoff; CelesTrak retry without a second download; news and Kp through the
491Worker; DSN Now freshness; NASA/ESA image licences; 26 LoC plates bundled.
492
493** v4.3: widgets and controls
489494- Lock Screen: Kp, next launch. Home Screen: Voyager 1 distance, today's Sun
490 image.
495 image. Done; not yet checked on a device.
491496- Widgets and Control Center controls backed by the App Intents, with an
492 App Group.
493- Opt-in notification for a visible ISS pass in 15 minutes (local).
497 App Group. Done: App Group =group.sh.krz.moonrise= shares the Sky tab's
498 place; controls open Sky, Sun and Launches.
499- Opt-in notification for a visible ISS pass in 15 minutes (local). Done.
494500
495501** v5.0: eclipse, 2 August 2027
496502- Watch haptics at second and third contact.