HKObserverQuery BackgroundDelivery not executed

Hi,

before installing iOS 15 our app received HKObserverQuery calls in background, which worked like a charm - the calls have reliably woken up our app in background, enabling it to process new HK data.

In iOS 15 the new entitlement com.apple.developer.healthkit.background-delivery was added, being mandatory if HKObserverQuery calls should be delivered in background. Indeed, we added the entitlement to the Entitlements file and the Provisioning Profile of the app. After doing so, registering with enableBackgroundDelivery(for:frequency:withCompletion:) worked again without an error.

While testing we observed that the app is not called at all. To debug, we captured system logs of an iPhone with iOS 15 - you can find them attached.

It can be seen that HK background delivery tries to fire, but dasd decides to not proceed because of the ApplicationPolicy.

After some research we found this might be related to background modes capabilities. Thus we added "Background fetch" and "Background processing". Anyhow, this did not change the behavior.

Again, this background delivery perfectly worked on iOS 14 - we did not change anything except adding the new background delivery entitlement (and the background processing entitlements in a second try).

Are we missing any (new?) entitlements? Any other news in iOS 15 making further changes necessary? Is HKObserverQuery working for others in background mode?

Thanks in advance for considering and best regards, Nils

Notes on the logs:

  1. App was suspended at all times
  2. iPhone was unlocked from the beginning on
  3. iPhone was locked at 13:16

Shit, I also ran into a similar issues.

But mine is more confusing. Mine can work for a while, but after four or five times event was triggered it stops working until I reopen the app.

The runs which go through might appear while your app is open (or not yet suspended after returning to the home screen) - at least this is the behavior at my side.

In the meantime I opened a TSI case, provided a sample project and already got response: The technician thinks this might be a bug and asked me to create a bug report. He also told me that he is going to assign the bug report directly to the HealthKit team. I am working on creating a bug report until noon (CEST).

Going to provide updates here...

Nils-B, any update? I think we're seeing the same problem.

Hi,

the technician from TSI told me that he considers this as an iOS 15 bug. He asked me to create a bug report, which I did. After I created the bug report, he assigned it to the Health team. However, I was also informed that "due to privacy" he is unable to provide me with further updates on this - which is quite poor in my point of view...

He also asked me to test this with iOS 15.1 beta, as it might be a bug, which got fixed there. I upgraded one of my employer's iPhones to 15.1 to test this, however I was occupied with some other duties the last days, so I could not test in detail (just in parallel to web meetings 🙄). On iOS 15.1 I did not see the "ApplicationPolicy / Must not proceed" messages on the console, but that might be caused because I didn't test properly.

I would appreciate if you could test on 15.1 beta as well. I would enclose your experiences and a link to this thread in my next reply to TSI.

Best, Nils

iOS 15.1 beta 3 test so far is inconclusive. One app got some limited background processing time, but the test is confounded by having Background Modes checked for Background fetch and Background processing. Disabling those now. The other app, which works fine on iOS 14, didn't get any processing time.

default	11:12:21.732196-0400	dasd	com.apple.healthkit.background-delivery.tld.domain.app1:094E1A:[
	{name: ApplicationPolicy, policyWeight: 50.000, response: {Decision: Must Not Proceed, Score: 0.00}}
 ], FinalDecision: Must Not Proceed}

default	11:12:21.732573-0400	dasd	com.apple.healthkit.background-delivery.tld.domain.app2:F09C36:[
	{name: ApplicationPolicy, policyWeight: 50.000, response: {Decision: Must Not Proceed, Score: 0.00}}
 ], FinalDecision: Must Not Proceed}

default	11:12:21.734499-0400	dasd	com.apple.healthkit.background-delivery.tld.domain.app3 (production app):53F125:[
	{name: ApplicationPolicy, policyWeight: 50.000, response: {Decision: Must Not Proceed, Score: 0.00}}
	{name: FileProtectionPolicy, policyWeight: 0.010, response: {Decision: Absolutely Must Not Proceed, Score: 0.00, Rationale: [{classALocked == 1 AND activityFileProtection == <File Protection: ClassA>}]}}
 ], FinalDecision: Absolutely Must Not Proceed}

Then I got lines like this, but only for the production app:

default	11:27:08.675816-0400	dasd	com.apple.healthkit.background-delivery.tld.domain.app3:53F125:[
 ] sumScores:68.598232, denominator:68.620000, FinalDecision: Can Proceed FinalScore: 0.999683}

default	11:27:39.184446-0400	dasd	COMPLETED com.apple.healthkit.background-delivery.tld.domain.app3:53F125 at priority 30 <private>!

Checked on iOS 15.1 Release Candidate - still no fix. The TSI engineer told me to check each new beta, as this will be the fastest way to determine, if a fix was included... However, I did not receive a formal confirmation that a bug exists, however I was told that the Health team has no inquiries regarding my sample project - this could interpreted as "they are able to reproduce it".

In general the communication on this issue is quite frustrating, as one is unable to receive reliable statements from Apple. I wonder if they are aware of this bug in the team in charge of these HK queries...

Update - it looks like the my test apps do get launched into the background, but less frequently on iOS 15 compared to previous versions. Sometimes days without a background launch. I haven't launched the app manually into the foreground since starting the test on October 5, 2021.

Also experiencing this issue with healthkit background refresh.

Issue is persisting in iOS 15.2 beta - updated the ticket. Starting to be skeptical about a fix in near future... I tried to receive a tech talk slot, but was unlucky twice.

By the way: I observed a few background launches, already described by jlc3, as well. However, these became way to seldom (i.e. every few days using .hourly data types).

I'm having a similar issue with watchOS 8.1. The background delivery stops working approximately 2-4 hours after the app went to the background. For example, I'm receiving updates during the evening from the app, but then over the night updates stop delivering and I'm getting those only if I open the app again in the morning.

I am seeing the same messages in the console on iOS 15.2. It seems to only occur if the app has been force quit by the user.

A first test iOS 15.2 beta 3 shows that a background delivery fires successfully roughly half an hour after suspending the app. The background processing took 31 seconds and was not cancelled by iOS.

Seems like we are approaching a fix, finally. :-) Happy to hear from your test results.

I was just able to confirm the fix in iOS 15.2 release. Happy updating! 🎉

Thanks for confirming that iOS 15.2 fixes this. Please file a new report if this isn't resolved for you or if there are any additional issues in 15.2. Thanks!

Seems broken again in iOS 16.0

HKObserverQuery BackgroundDelivery not executed
 
 
Q