Description
I've observed that the app does not consistently send queued events when it is terminated. Here's a summary of the issue and findings:
Context
We've implemented the app on both iOS and Android now, and the ratio of events logged between the two platforms does not match our user pool.
Using a proxy, I confirmed that when the app is terminated, events are not always sent.

Root Cause
Upon investigation, I found that the stopPolling function is triggered by observing UIApplication.didEnterBackgroundNotification. However:
Observing didEnterBackgroundNotification does not guarantee async work completes before the system terminates the app.
According to Apple's documentation, this notification is more suitable for cleanup tasks like freeing resources, saving user data, or invalidating timers, not for performing async operations.
Proposed Solution
A more reliable approach would be to observe UIScene.willDeactivateNotification instead. This notification is triggered as soon as the app is no longer active (e.g., when the user switches apps), providing an earlier opportunity to flush queued events.
Suggested Fix
Replace the observer for UIApplication.didEnterBackgroundNotification with UIScene.willDeactivateNotification to trigger the stopPolling function earlier.