Commit a866e469a3

a866e469a3568bf7a2829a8dd2a56317ced4736e

parent: effed25309

Verified · cmc

cmc <hello@cleberg.net> · 2026-10-10 19:42 UTC

iOS: ask for badges when they're off

Notifications granted before the app asked for badges leave Badges out of its notification settings. The app asks again while badges are off, which adds them; Settings has a button that asks and, when badges stay off, opens the app's notification settings.

Layout: unified · split

Sources/OrgstarMobile/MobileModel.swift +12 −1
@@ -272,7 +272,7 @@ final class MobileModel {
272272 /// that only changes the badge.
273273 private func updateBadge(_ counts: [Int]) async {
274274 let center = UNUserNotificationCenter.current()
275 guard await SystemReminderCenter().authorize(), await center.notificationSettings().badgeSetting == .enabled else { return }
275 guard await badgesEnabled(asking: true) else { return }
276276 try? await center.setBadgeCount(counts.first ?? 0)
277277 center.removePendingNotificationRequests(withIdentifiers: (1..<AgendaSnapshot.dayCount).map(Self.badgeID))
278278 let today = Calendar.current.startOfDay(for: Date())
@@ -287,5 +287,16 @@ final class MobileModel {
287287 }
288288
289289 static func badgeID(_ offset: Int) -> String { "badge.\(offset)" }
290
291 /// Whether iOS shows the icon's badge. Asking adds badges to the app's notification
292 /// settings, which an earlier grant without them leaves out; iOS prompts only the first time.
293 func badgesEnabled(asking: Bool) async -> Bool {
294 let center = UNUserNotificationCenter.current()
295 let settings = await center.notificationSettings()
296 if settings.badgeSetting == .enabled { return true }
297 guard asking, settings.authorizationStatus != .denied else { return false }
298 _ = try? await center.requestAuthorization(options: [.alert, .sound, .badge])
299 return await center.notificationSettings().badgeSetting == .enabled
300 }
290301}
291302#endif
Sources/OrgstarMobile/SettingsScreen.swift +25
@@ -11,6 +11,9 @@ struct SettingsScreen: View {
1111 let model: MobileModel
1212 @State private var choosing = false
1313 @State private var calendars: [CalendarChoice] = []
14 @State private var badges: Bool?
15 @Environment(\.openURL) private var openURL
16 @Environment(\.scenePhase) private var scenePhase
1417
1518 private struct CalendarChoice {
1619 let id: String
@@ -59,6 +62,26 @@ struct SettingsScreen: View {
5962 } footer: {
6063 Text("org-enforce-todo-dependencies and org-enforce-todo-checkbox-dependencies.")
6164 }
65 Section {
66 if badges == true {
67 LabeledContent("Overdue Count on Icon", value: "On")
68 } else if badges == false {
69 Button("Show Overdue Count on Icon…") {
70 Task {
71 if await model.badgesEnabled(asking: true) {
72 badges = true
73 await model.updateWidgets()
74 } else if let url = URL(string: UIApplication.openNotificationSettingsURLString) {
75 openURL(url)
76 }
77 }
78 }
79 }
80 } header: {
81 Text("Badge")
82 } footer: {
83 if badges == false { Text("Turn on Badges in orgstar's notification settings.") }
84 }
6285 calendarSection
6386 Section("In use") {
6487 let _ = model.settingsVersion
@@ -71,6 +94,8 @@ struct SettingsScreen: View {
7194 }
7295 }
7396 .navigationTitle("Settings")
97 // Read again on return from the Settings app.
98 .task(id: scenePhase) { badges = await model.badgesEnabled(asking: false) }
7499 .fileImporter(isPresented: $choosing, allowedContentTypes: [.folder]) { result in
75100 if case .success(let url) = result { model.setConfigFolder(url) }
76101 }
docs/manual/guide/14-ios.org +1 −1
@@ -262,7 +262,7 @@ With =reminders= on, orgstar schedules a notification before each timed agenda e
262262
263263iOS lets an app schedule at most 64 notifications, and orgstar schedules more only while it runs. It updates them when files or settings change, when you return to the app, and every hour while it is open. The agenda's status line says how far ahead reminders are set ("Reminders are set through …"), or that notifications are off for orgstar in the system Settings app.
264264
265The app icon's badge counts the entries in the agenda's Overdue section that aren't done: past their scheduled day or their deadline, habits left out. An entry past both counts once. orgstar sets each of the next six midnights' counts ahead, so the badge stays right while the app is closed. Turn it off in Settings ▸ Notifications ▸ orgstar ▸ Badges.
265The app icon's badge counts the entries in the agenda's Overdue section that aren't done: past their scheduled day or their deadline, habits left out. An entry past both counts once. orgstar sets each of the next six midnights' counts ahead, so the badge stays right while the app is closed. If notifications were allowed before orgstar asked for badges, tap Show Overdue Count on Icon under Badge in orgstar's Settings; it adds Badges to orgstar's notification settings and opens them when they're still off. Turn the badge off there, under Badges.
266266
267267* Export
268268