I am trying to get the data from the barometric altimeter sensor on apple watch.
I tried using the apple documentation (it worked for accelerometer and gyroscope) but when I tried to use the methods documented in the CMAltimeter class, it did not recognize any of it (related to the altimeter).
I need to build a watch app that tracks the user movement, so I need to use CoreMotion.
I searched about this feature in watch and I didn't find any useful tutorial.
my question is:
is it possible to record CoreMotion data in Apple watch and then share it on a server somewhere?
I have created a heart rate monitor on the apple watch and that sends alerts to notifies you if your heart rate gets to low. After creating the app, I realized it does not run in the background. Is there a way to either force the app to run in the background on the watch or send the heart rate information to the phone?
I've investigated this, but don't have any practical experience (yet).
From what I understand, watch apps in watchOS3 can capture continuous heart rate updates with these conditions:
It's a full app (not just an extension).
The app starts a workout
Info.plist has the WKBackgroundModes key set
You'll need to either start the workout from the watch app, or if triggered from the companion iOS app you'll need to call startWatchAppWithWorkoutConfiguration:completion: to start a workout session on the paired watch.
p.s. welcome to stackoverflow!
I need to make an app that records heart rate data in near real time and send this data to a server as soon as possible.
First I took this approach: Watch os 2.0 beta: access heart beat rate
In fact it is working fine. There is new heart rate data in the HealthKit every five seconds. But now I have the problem that I can't sync that with a server.
My first approach was the Watch app. The watch was sending data to a server. That doesn't work because as soon as the screen turns black on the watch, it stops sending.
My next approach was to query the HealthKit on the iPhone every five seconds for new data. This works, as long as the app is in foreground.
Then I saw that there's some kind of background functionality that watches the HealthKit itself and revokes the app from background and you can do something.(enableBackgroundDeliveryForType) This doesn't seem to work for heart rate (the Apple Documentation says for things like steps this doesn't work, I guess heart rate is one of those).
I'm stuck now. Do you know how to it? I would need some background task that is executed every 5-10 seconds on the iPhone. That seems to be impossible
UPDATE
As noticed by #BootMaker, Apple made background mode available for HKWorkout apps in WatchOS 3, so it's working now. You have to run a HKWorkoutSession and this will keep your heartrate delivery in real time even when the app is in the background (dark screen on watch)
The closest you are going to be is while the watch app is open.
Why I'm stating this?
There are two HealthKit's Database (one at the iPhone and another at the Apple Watch). When they sync is arbitrary and decided only by the O.S.
The closest you are going to be to real time is when you don't have any password locking your screen in iPhone or Apple Watch.
Either way, there's no guarantee that the sync will happen every time a new measure is added to Apple Watch's HealthKit
The only way to force the Heart rate sensor into working in real time is via workouts or observer while your Apple Watch app is in FOREGROUND.
Background delivery is NOT available for Apple Watch apps.
Watch OS 2 request the sensor to measure automatically (in background) every 10 minutes minimum.
There's no other workaround, if you need real time for longer periods, or while the user is not using your app, you will need to use an specialized wearable.
If anyone still need to get heart rate or other data in real time. Use this solution:
Develop an apple watch app/extention
In watch app, using HKHealthStore, HKWorkoutConfiguration, HKWorkoutSession, HKLiveWorkoutBuilder to create an Workout. After create workout, your watch app will get heart rate in real time.
Using watch kit connection with WCSession to send data to iPhone app.
Enable background mode both in apple watch and iPhone.
I tested, even app terminated, we can still get heart rate (I used Local notification for posting heart rate data for debugging)
Is there any way to learn under iOS using C code how many times the battery has been charged?
Thanks.
Not via any public APIs. According to the UIDevice documentation, it appears the most you can do is get the battery charge level, its state, and enable battery monitoring.
Get Device Battery State