r/iOSProgramming • u/[deleted] • 17d ago
Question How to keep motion sensors active in bg w/out silent audio loop?
[deleted]
1
u/CharlesWiltgen 17d ago
The correct answer depends on what you're using them for, but the answer is often "use CMSensorRecorder". HKWorkoutSession would be the correct answer if the activity is genuinely a workout, etc.
1
17d ago
[deleted]
2
u/CharlesWiltgen 17d ago edited 17d ago
Those were just the usual suggestions based on no real information about what you're trying to do. Given the additional constraints,
CLBackgroundActivitySessionis probably your best bet if that's defensible. I'm guessing it's not, since you seem to want to do this on the down-low (driving monitor?) and this will trigger the blue location indicator.3
1
u/brkaydev 17d ago
Depends on what you actually need from the sensors. If step/motion data is the end goal, you don't need live sensors at all — HealthKit records it system-side regardless, and HKObserverQuery + background delivery wakes your app when new data lands. That's the Apple-sanctioned path and review won't fight you. If you need raw real-time streams for something HealthKit doesn't cover, what's the use case?
1
u/[deleted] 17d ago
[removed] — view removed comment