bitstadium / HockeySDK-iOS

HockeyApp was retired and the SDKs are deprecated. Please use App Center instead.
https://github.com/microsoft/appcenter-sdk-apple
Other
597 stars 268 forks source link

Event tracking doesn't play nicely with background tasks #474

Closed evl5051 closed 6 years ago

evl5051 commented 6 years ago

We're tracking events in a background task which is kicked off from an actionable notification. In Apple's documentation, they recommend that we call [UIApplication endBackgroundTask:] when we're finished with the task. This method call immediately stops the background task.

There are a few situations where we call [BitMetricsManager trackEventWithName:] just before we would end the background task, e.g. to record success or failure. Unfortunately, we cannot just call endBackgroundTask after trackEventWithName returns, since trackEventWithName is asynchronous. If we do, there's a race condition where the event may or may not get tracked before the task gets killed.

Of course, we could just introduce an artificial delay of 1s or so before calling endBackgroundTask, but that feels hacky to me. Is there any official recommendation on what route to take here?

ElektrojungeAtWork commented 6 years ago

Hey @evl5051, we have a PR ready for this and it will be part of the next release which is scheduled for late November/early December.

Thx for reporting this and apologies for the inconvenience.

Best, Benjamin

ElektrojungeAtWork commented 6 years ago

Let's leave this open until it's released.

ElektrojungeAtWork commented 6 years ago

We just released 5.1.0 which addresses this. I'm closing this issue.