简体   繁体   中英

HKObserverQueryCompletionHandler timeout?

I use HKObserverQuery and background delivery in my iOS application. In the updateHandler of HKObserverQuery I execute a query ( HKAnchoredObjectQuery ) and send results to the remote server via https. But on a slow connection (EDGE for example) and with big amount of data (steps for example) data sending may take up to one minute.

From the documentation to HKObserverQueryCompletionHandler:

When HealthKit wakes your app, it calls the update handler on any observer queries that match the new data. This block is passed to the update handler. You must call this block as soon as you are done processing the incoming data. Calling this block tells HealthKit that you have successfully received the background data. If you do not call this block, HealthKit continues to attempt to launch your app using a back off algorithm. If your app fails to respond three times, HealthKit assumes that your app cannot receive data, and stops sending you background updates.

So my question is: How much time do I have to call HKObserverQueryCompletionHandler before my app is assumed by HealthKit as "hanged"? Or should I call HKObserverQueryCompletionHandler immediately and run a new long-running background task for https request instead?

You should definitely start a separate background task to perform the transfer of data to your server and call the HKObserverQueryCompletionHandler as soon as possible. The documentation gives no indication as how long you can wait before calling the handler so the safest thing to do is call it as soon as possible.

I posted a similar question about confusion around use of HKObserverQueryCompletionHandler here , but there haven't been any updates.

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