How I Built an iPhone App That Unlocks Screen Time With Exercise
Counting push-ups from Vision body pose with one state machine, and what Screen Time's shields, callbacks and 20-activity limit really allow.
Pull to Refresh is an iPhone application designed to lock chosen apps and unlock them through exercise repetitions monitored by the camera. The app relies on Apple's Screen Time API to count reps and employs a state machine for managing exercise states. It processes data from the front camera feed, extracting joint positions at a frame rate of 30 FPS.
Joints with a confidence of 0.3 or higher are retained, while frames lacking sufficient joint data are ignored. The app supports various exercises, including push-ups, squats, sit-ups, pull-ups, and jumping jacks, each with defined joint angle thresholds and minimum required intervals between reps. The counter maintains one Double value for each exercise, with values oriented so that lower values indicate contracted positions and higher values suggest extended positions.
The app features a state machine that scores all five exercises, using two thresholds and a speed limit for each. The application is split into separate processes, with an App Group Screen Time functionality allowing workload distribution. It utilizes shield extensions to manage the lock screen and its buttons, with another extension responsible for reporting activity.
The app's design ensures that the user can monitor their Screen Time progress by seeing the count without revealing the underlying numbers. The app's architecture allows for easy management of rules and activities, with each rule having its own ManagedSettingsStore. The monitor process is kept separate from the others, receiving only the activity name, and uses a policy function to decide whether to open or keep a rule active.
This approach ensures that the screen can be unlocked without triggering further changes, even when a save operation is triggered. The app is designed to adhere to certain limitations, such as monitoring a maximum of twenty activities and allowing a minimum interval of fifteen minutes between each activity.
Rewritten by urgent.news; may contain errors — check the original.
Source: hackernoon.com