iOS push notification permission: ask after a real task
Set the reminder first, then ask for iOS push notification permission. Check delivery on a real device. A simulator pass does not show that the alert arrived.
The worst time to ask for iOS push notification permission is on the first screen after install, before the user has done anything useful or knows whether the app is worth keeping. A refusal on launch usually closes that channel permanently.
I haven't shipped a large-scale remote push backend, yet I've built the adjacent native pieces: local notifications, a WidgetKit extension fed from an App Group snapshot, and an airspace safety app where stale state must never look fresh. Most apps treat notifications as a growth toggle when they're actually a promise about the world at a specific time.
iOS push notification permission is earned after a useful moment
Ask only after the app has shown a concrete future benefit. In a child health log app I built, that moment arrives after a parent enters a medicine interval and chooses to set a reminder; the system prompt changes from "Can this unknown app interrupt me?" to "Do I want the reminder I just configured?"
First-launch prompts also compete with location, photos, and sign-in, making the app look desperate for access. A cleaner flow takes three steps: let the user finish the core task without a prompt, put the reminder toggle inside that flow with plain wording about timing, and trigger the OS permission dialog only when they enable it. Don't build a fake pre-prompt whose only purpose is to funnel people into "Allow"; explain what still works if they decline, and leave a quiet settings link for later if they change their mind.
Most events do not deserve an interruption
If a user wouldn't thank you for interrupting them right now, don't send the alert. Feature announcements and two-day retention nudges serve the company, whereas a medicine interval ending or a time-sensitive change gives the user a real choice.
Design the notification budget for the whole account in one explicit policy function covering authorisation, enabled categories, the last interruption, higher-priority alerts, and whether the underlying state is still true. Otherwise separate features pile up alerts on one Lock Screen. In the airspace safety app I built, the client starts unavailable, caches API responses with If-None-Match and ETags, and keeps a previous verdict for only five minutes after a failed check before returning to unavailable; the Cloudflare Worker likewise returns 503 UNAVAILABLE instead of CLEAR when a bundle or geometry check fails. Alerts need the same honesty: if the data isn't fresh enough to support the claim, say less.
Use local notifications for device-owned reminders
Local notifications schedule directly on the device without needing a server to call APNs when they're due, which makes them the right fit for timers, appointments, and personal reminders. In the child health log app, a parent enters a medicine name, dose text, and optional minimum interval (parent-entered data, not medical advice), and local scheduling handles the reminder with zero server round trips.
Use remote delivery only when another device creates the event, people need to coordinate, or server state decides it. Remote push is best-effort anyway, not a delivery receipt, and it brings APNs credentials, token churn, backend jobs, and failure handling. Whichever path you use, give each item a stable identifier, remove and replace pending requests on edit, remove them on completion, and pass an opaque ID in userInfo so tapping the banner loads fresh state instead of trusting stale payload text.
Widgets and notifications need one state contract
A widget is a separate extension process, not a tiny copy of your app. In the child health log app, the WidgetKit extension never reads Core Data directly; after launch, a child switch, or a save, the app computes a small Codable WidgetSnapshot, writes widget-snapshot.json atomically to the shared App Group container, and calls WidgetCenter.shared.reloadAllTimelines().
Sharing one source of truth keeps the widget and notifications from contradicting each other. Store dose state as a raw due date so the widget timeline can flip exactly when the interval ends (with a 30-minute refresh fallback for day rollovers) and the notification schedules from that same date, instead of pre-rendering sentences separately. Atomic file writes matter because the widget must decode either a complete old snapshot or a complete new one, and privacy matters just as much: mark health lines privacySensitive on the widget and keep Lock Screen notification previews discreet enough that a medicine name or symptom isn't exposed to anyone glancing at the phone.
State changes make scheduled alerts stale
A scheduled notification is just a snapshot of an intention, so any edit, deletion, or CloudKit sync from another caretaker can make it wrong. Don't scatter add and removePendingNotificationRequests calls inside SwiftUI views, which appear and disappear for layout reasons; put reconciliation next to the save coordinator, make it idempotent, and run it after saves, syncs, and foreground returns.
For remote notifications, include an event version or timestamp and load the latest record on tap, including when the event is already resolved. Never make push the only way to see a change, because permissions get denied, Focus modes hide banners, and devices go offline; anything important still needs an in-app badge, inbox, or state indicator.
The simulator cannot prove the behaviour you sell
Unit tests on an in-memory Core Data stack catch derived-state bugs like dose-gap maths, medicine formatting, and midnight rollovers, yet they can't prove a locked phone, a terminated app, a months-old permission refusal, or a time-zone change. Delivery has to be checked on real hardware:
- Install fresh and confirm the core flow works before any permission prompt appears.
- Deny permission, set a reminder, and verify the app explains the missing channel without nagging.
- Allow permission, schedule an alert, lock the phone, and wait for it to fire.
- Edit, complete, and delete an item before its due time and confirm the old alert never arrives.
- Switch the focused child or synced data and check that the app, widget, and pending reminder agree.
- Cross a time zone and a midnight boundary, kill the app, restart the phone, and verify locked-screen privacy previews.
Hardware testing also shows that widget reloads and background tasks aren't precision clocks; Focus modes and system scheduling delay them, so a late alert has to be harmless and the app itself must always show the current truth. For how I test behaviour at the contract boundary, read tests as contracts.