Hkanchoredobjectquery Not Returning Reliably in Background

Healthkit multiple HKAnchoredObjectQuery not returning data for all sample types

This is expected. The query's initializer takes a type parameter only returns results of that type. You cannot query for multiple types of samples with a single query.

HKAnchoredObjectQuery updateHandler not being called

My UITableViewController was in a UIPageViewController. viewDidAppear() on the UITableViewController does not get called when returning from the detail screen, so I assumed viewDidDisappear() would not get called as well and I was stopping the query in there. My assumption was wrong.

A question on where to stop long running HKQuerys: Do HKQuery's need to be stopped in View Controllers

How do I use Healthkit observer queries with background delivery without prompting non-HK users for permissions?

One possible flow is:

  • In didFinishLaunching, check UserDefaults for a Boolean that indicates the user has approved HealthKit integration. If it is true then call a function to set up your observer queries.

  • At the point in your app execution where the user indicates that they want to provide access to HealthKit data, prompt for permission and then set the Boolean in UserDefaults once you have permission.

  • At this point you would also call your function to set up your observer queries so that you start receiving data.



Related Topics



Leave a reply



Submit