HealthKit Not Working in the Background of Xamarin.Forms Anymore—What To Do!

I recently updated the Nuget packages of an Xamarin.Forms application which accesses health and physical activity data in iOS and has been doing it successfully for a long time. One of the libraries to update was the third-party library responsible for taking the data from HealthKit and preparing it to be sent to the server.

After the update, I verified that the synchronization was still working, and we sent the application to the users. At first the application seemed to work correctly, but when it went into the background, the synchronization stopped. This behavior was rare since the update and documentation of the library did not indicate the need for any changes for this new version.

Upon retesting the app in the background, I found that it was failing with an insufficient permissions message. This happened because iOS, starting from version 15, needs a new entitlement to access health information in the background. After adding com.apple.developer.healthkit.background-delivery to the entitlements list, everything started working fine.

If you run into the same change, I hope this tip helps you fix it quickly, or avoid it all together.

References

https://developer.apple.com/documentation/bundleresources/entitlements/com_apple_developer_healthkit_background-delivery

Picture of Rodrigo Juarez

Rodrigo Juarez

Rodrigo Juarez has over 25 years of experience in software development, specializing in Microsoft technologies. His mission is to solve complex problems for his clients, with a focus on results. He achieves this by applying the appropriate technology and using best practices to ensure the delivery of high-quality solutions. Over the past 6 years, Rodrigo has honed his skills in back-end development and in creating mobile applications, initially using Xamarin and now transitioning to .NET MAUI. He is a Lead Mobile Developer at Trailhead Technology Partners and the co-author, along with Jesse Liberty, of the book ".NET MAUI for C# Developers"

Free Consultation

Sign up for a FREE consultation with one of Trailhead's experts.

"*" indicates required fields

This field is for validation purposes and should be left unchanged.

Related Blog Posts

We hope you’ve found this to be helpful and are walking away with some new, useful insights. If you want to learn more, here are a couple of related articles that others also usually find to be interesting:

Our Gear Is Packed and We're Excited to Explore With You

Ready to come with us? 

Together, we can map your company’s software journey and start down the right trails. If you’re set to take the first step, simply fill out our contact form. We’ll be in touch quickly – and you’ll have a partner who is ready to help your company take the next step on its software journey. 

We can’t wait to hear from you! 

Main Contact

This field is for validation purposes and should be left unchanged.

Together, we can map your company’s tech journey and start down the trails. If you’re set to take the first step, simply fill out the form below. We’ll be in touch – and you’ll have a partner who cares about you and your company. 

We can’t wait to hear from you! 

Thank you for reaching out.

You’ll be getting an email from our team shortly. If you need immediate assistance, please call (616) 371-1037.