How can I use HealthKit to actively monitor decibel levels over a threshold? - swift

I wish to build a timer with a start button that once pressed begins to monitor environmental decibel levels through HealthKit. And then once a decibel passes a threshold I wish to log event.
Is something like this available through health kit? Can I actively monitor decibel levels of my environment? Almost as how the native Noise app currently works on the Apple Watch. But I wish to gather this data when the user clicks a start button.
If so, how often can I sample this data? Can I get distinct decibel events that occur between each other within less than a second? A half second? A tenth of a second?

Related

How can apps like Autosleep get days of historical motion sensor data?

I want to replicate some of the functionalities of sleeptrakcing apps like AutoSleep. Apparently I can not open the app for a day or two, and when I open it up, it can accurately access the sensor data on my Apple Watch to see if I'm moving or not at any given 15 minute interval.
I've tried looking at various functionalities of CoreMotion. The closest I've seen is using CMSensorRecorder and call recordAccelerometer to start recording. However, this only allows you to record up to 12 hours. And the user would have to start the app to start recording. This is clearly a limitation that AutoSleep doesn't seem to have, because it seems to get the data out of thin air.
Anyone know how it's possible to get historical Accelerometer data from WatchOS that stretches back a long time without actively recording it?

Data types produced by apple watch

Does anyone have a list of data types that produced by the apple watch without any additional apps or integrated devices? It must be a subset of these, but I can't figure out which ones
The exact list of data types depends on the model, but the latest Apple Watch models automatically collect data for all of the following HealthKit types:
Active energy
Basal energy
Environmental audio exposure
Headphone audio exposure
Noise notifications
Exercise minutes
Flights climbed
Heart rate
Heart rate variability
Resting heart rate
Walking heart rate average
High heart rate notifications
Low heart rate notifications
Stand hours
Stand minutes
Step count
Walking + running distance
VO2 max
Apple Watch will also collect cycling distance, but only if the user explicitly records a cycling workout. There are also other types of HealthKit data that can be recorded manually by the using the built-in apps on the Apple Watch, such as mindful minutes.

watchOS get activity data

How can I go about capturing daily activity data from Apple Watch at a high level (gyroscope and accelerometer data) or is that not possible (due to current limitations of the API)?
I am trying to figure out a way to find all occurrences of a custom workout performed during the day by a watch user. User installs the app, grants permissions where applicable. Launches daily to see workouts performed in the last day. The app pulls data, stores it, analyzes it and plots necessary metrics.
I want to know if this is possible - pulling data on launch to run analysis. If so, how?
I see this example from Apple on recording counts swings in a racquet sport but that seems to require instantiating and stopping various CoreMotion events such as startDeviceMotionUpdates and stopDeviceMotionUpdates in order for the app to retrieve them.
Any pointers?

Time based GPS location in background (iphone)

I want to create an (game based) iPhone application which sends your GPS location on a specific time (like 3-5 times a day) to a server. I found an apple page explaining some functionality to run in the background like location, music and VOIP.
I need the GPS to be accurate on the meter.
Can someone help me with a small example?
It really depends on your usage of the location. If you monitor actively, kiss the battery of your user goodbye. Very detailed accuracy, even bigger hit to battery. The backgrounding of location is all or nothing as far as accuracy goes.
Less hit, less accuracy is -startMonitoringForSignificantLocationChange. May not be accurate enough for you.
Better depending on usage, region monitoring. Triggers event on entry or exit of defined region.
You don't have the benefit of accuracy and timed location based events. You can do it, but is going to require a lot more effort on your end.
While this is untested, I am planning an app with a similar need. My solution is that on a significant location change, the app will determine what interval exists between the update timestamp, and when I care to know the users location (5pm for instance). If that's below some threshold, it will go into startUpdatingLocation mode (full power, battery draining, which is why that threshold is important) and then, on each location update, check if that target time has passed. if SO, send the update to your server, and go back to monitoring for significant changes. The catch is that if it still requires some movement to trigger the significant change update...so it isn't a perfectly reliable solution, but it may work depending on how you're using the data
You can't "schedule background work". iOS doesn't allow it.
The solution is to set yourself up for notification on significant change (which is some hit to the battery, but it's not horrible), and then only DO anything with that at occasional intervals.

Is there any way to check if there is any input to the mic or not?

Is there any way to let's say, user clicks a button, and then he needs to say something to the mic, but only after he finishes to talk to the mic, the app will wait 5 seconds, and then the app will do something. is there any code or example for this? to check if there is an input to the mic or not.
thanks in advance!
If you're recording with AVAudioRecorder, you have the ability to enable metering and get basic power metrics for your current recording. One way to determine silence for a period of time is to sample the average power and peak power over a time period of your choosing (1/2 second to a few seconds). If the ratio remains low enough during that arbitrary period, the input has been relatively quiet and you can end the recording. You can view the docs for that class here. If you're using Audio Queue Services, this may be a little more involved, but the concept is the same.