AI Health Recommendations Based on Mobile Health Data
Most health apps show users numbers—and they close the app without changing habits. We change the scenario: instead of "here's your data" we give "here's what this data means for you today." According to HealthKit, the average user's daily activity is 5,423 steps, sleep—7.1 hours. Based on this data, our rule engine generates 12–20 candidate recommendations per day, and ML ranking selects 3–5 most relevant ones. For example, if resting heart rate is above 80 bpm and sleep is below 6.5 hours, the recommendation is to reduce workout intensity.
In this article, we explain how we build a recommendation system: from data collection to push notification delivery. You'll learn why a rule engine is not a relic but a foundation, and how ML adds personalization without losing transparency. We have developed 15+ health apps and have extensive experience; one of our projects reached 500,000+ installs. If you need a similar system, contact us—we'll help design and implement it.
Why a Rule Engine Is the Foundation of Personalized Recommendations
Rule-based approach is not outdated—it's practical. Rules are transparent, testable, and require no dataset for training. ML on top of rules adds personalization in ranking. Combined conditions matter: a resting heart rate of 85 bpm alone may be normal, but combined with sleep deprivation, it's a marker of overtraining.
Recommendation System Architecture
Personalized health recommendations are a pipeline with multiple layers, not a single algorithm. The table below outlines the main components.
| Layer | Purpose | Example Technology |
|---|---|---|
| Data collection | Raw metrics acquisition | HealthKit, Health Connect, Core Bluetooth |
| User profile | Age, goals, behavior patterns | Realm / Core Data |
| Feature engineering | Aggregation into meaningful metrics | Swift Combine / Kotlin Flow |
| Rule engine | Transparent conditions with priorities | Custom Swift/Kotlin |
| ML ranking | Personalization of candidates | Gradient boosting (XGBoost) |
| Delivery | In-app / push with optimal timing | UNNotification / FCM |
Data: HealthKit as the Single Point on iOS
class HealthDataAggregator { private let store = HKHealthStore() func weeklyStats() async throws -> HealthWeekSnapshot { async let steps = fetchSum(.stepCount, days: 7) async let sleepHours = fetchCategorySamples(.sleepAnalysis, days: 7) async let restingHR = fetchAverage(.restingHeartRate, days: 7) async let activeEnergy = fetchSum(.activeEnergyBurned, days: 7) return try await HealthWeekSnapshot( avgDailySteps: steps / 7, avgSleepHours: sleepHours, avgRestingHR: restingHR, totalActiveKcal: activeEnergy ) } } On Android, we use Health Connect SDK with HealthConnectClient.readRecords(StepsRecord::class) to query steps for a period. We also connect third-party devices via Core Bluetooth on iOS and BLE on Android to get data from scales, blood pressure monitors, and fitness bands.
How ML Improves Personalization
The rule engine generates a list of recommendation candidates. The ML model ranks them by the probability of the user taking action. We use gradient boosting on features: historical CTR, day-of-week pattern, streak adherence. We train on implicit feedback: shown → opened → completed (data from HealthKit).
How Push Notification Timing Is Determined
The right moment matters more than content. "Go to bed earlier" at 20:00 works; at 23:30 it doesn't.
func scheduleRecommendation(_ rec: Recommendation) { let content = UNMutableNotificationContent() content.title = rec.title content.body = rec.shortBody content.sound = .default let bestTime = optimalDeliveryTime(for: rec, userSchedule: userProfile.typicalSchedule) let trigger = UNCalendarNotificationTrigger( dateMatching: Calendar.current.dateComponents([.hour, .minute], from: bestTime), repeats: false ) let request = UNNotificationRequest(identifier: rec.id, content: content, trigger: trigger) UNUserNotificationCenter.current().add(request) } optimalDeliveryTime analyzes user patterns: app opening time, sleep, workouts. Context binding: if CMMotionActivityManager shows the user is walking, don't show an activity recommendation.
Principles of Effective Recommendations
One specific recommendation per day beats five generic ones. "Walk 2,000 more steps by 6 PM, you're at 1,200 now" works. "Move more" does not. Context awareness and personalization are key drivers of engagement. We use A/B testing to select the most effective formats and content.
Work Process for Recommendations
- Analyze data sources and design HealthKit/Health Connect schema.
- Develop 20–50 rules based on medical protocols and typical scenarios.
- Implement ML ranking using synthetic data for training.
- Build delivery system: in-app widgets + push with optimal timing.
- Run A/B tests for at least 2 weeks.
- Document API and train the client's team on rule administration.
What's Included in Our Work
- API documentation for integration and rule management.
- Training the client's team on administering and customizing recommendations.
- Post-launch support for 3 months.
- Code warranty: fixing bugs within the specified architecture.
Timeline Estimates
| Stage | Duration |
|---|---|
| Rule-based MVP with basic recommendations | 1–2 weeks |
| Full system with ML ranking and timing | 3–5 weeks |
| A/B testing and refinement | +2 weeks |
Exact estimation depends on integration complexity and number of data sources. Contact us for a consultation—we'll analyze your project in 1 day. Get an individual proposal.







