Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
freem
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Openai/691a5ca1-2b1c-8010-8cbd-8797f95aa8d9
(section)
Add languages
Page
Discussion
English
Read
Edit
Edit source
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
Edit source
View history
General
What links here
Related changes
Special pages
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==== 4. How I’d wire motion + GPS + notifications + Live Activity together ==== High-level flow: ===== A. On “Start driving” ===== * Persist a new DrivingSession with startDate. * CLLocationManager: - activityType = .automotiveNavigation (or appropriate) - allowsBackgroundLocationUpdates = true - Reasonable desiredAccuracy / distanceFilter. * CMMotionActivityManager: - Start activity updates to refine “driving vs stopped”. * UNUserNotificationCenter: - Schedule a 4h local notification from “now” as a baseline. - Optionally schedule a 3h30 “pre-break” reminder. * ActivityKit: - Start a Live Activity with: - elapsed at 0 - targetBreakTime = now + 4h - optional fields: distance, average speed. ===== B. While session is running ===== Your engine (actor / object) receives: * Motion updates → determine “currently driving or not” * Location updates → compute: - distance - speed - optionally use timestamp deltas for more accurate time accounting. The engine: * Maintains driving seconds (don’t rely on a timer; use timestamps). * Whenever state changes enough (e.g. every 30s or significant change), it: - Updates Live Activity with the latest stats. - Optionally adjusts the planned notification fire time if your logic changes - But you can also keep it simple and just fire at exactly 4h from when they tapped Start. ===== C. On “Stop driving” ===== * Close the session (store endDate, total time, distance, etc.). * Cancel any future driving-specific notifications (if desired). * End Live Activity.
Summary:
Please note that all contributions to freem are considered to be released under the Creative Commons Attribution-ShareAlike 4.0 (see
Freem:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)