简体   繁体   中英

Healthkit: Set up 'enableBackgroundDelivery' but iOS is not at all waking up the app when there is new health data for the user on some devices

I'm working with HealthKit SDK on my app(it's related to Health). I set up 'enableBackgroundDelivery', expecting iOS to wake up my app whenever there is a new health data for the user so that I can start querying user's health data. iOS is waking up the app when there is new health data and the code is working as expected on my device and the user's device also, but on some devices, iOS is not at all waking up the app.

If there is an issue with my code, then it should not work for any device, but it's working with my device and on users' devices, so I think, there is very less possibility to have an issue with my code. When I search for the other possibilities for the issue, I have found the following reasons for iOS to not waking up the app when there is new health data for the user on some devices.

  1. Fitness Tracking and Health are turned OFF under Settings -> Privacy -> Motion & Fitness. And Motion Calibration & Distance is turned OFF under Settings -> Privacy -> Location Services -> System Services. In this case, the default Health app itself can't get health data, so it won't wake up my app.

  2. Background App Refresh is turned OFF for my app. In this case, when the app is minimized or force closed, HealthKit do not wake up my app because the user setup is as such.

  3. iOS intentionally do not wake up my app or any app frequently for so many reasons like to save user device's battery, or if the user is using so many apps actively then iOS gives the priority to those apps and iOS schedules our app's services to the future. iOS internal algorithms consider the device's performance and optimization and allocate the services to the apps installed on the device, it means that our code will be executed only when iOS decides it to be executed. This might be the reason why I don't see the health data for some users, but for how long? iOS should wake up my app at least after one or two days, but it didn't.


For the users I'm seeing the issue, the above # 1 and # 2 settings are set properly. If # 3 is the reason, iOS should wake up my app at least after one or two days, but it is not waking up the app, I have communicated with some of the users and they have some data in iOS default 'Health' app.


Did anyone experience this kind of issue? Did anyone have clue on any other reasons on why iOS didn't wake up my app than the above reasons(code wise and iOS settings wise)?

My code looks similar to this: https://gist.github.com/phatblat/654ab2b3a135edf905f4a854fdb2d7c8

Thanks.

I was looking around a lot, as I didn't get any updates from the background, even though I used the standard implementation from Apple and I enabled the HealthKit background delivery in the Capabilities.

Turns out - Background refresh has to be enabled in the Settings. At the very bottom of the HealthKit permissions dialog is written: "To allow background Updates enable Settings->General->Background Refresh ".

Even tough my app is not even listed there, this did the trick. I had disabled it by default, so maybe this is helpful for someone.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM