Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delay SDK initialisation until protectedDataDidBecomeAvailableNotification #213

Open
ioannisj opened this issue Oct 14, 2024 · 2 comments
Open
Assignees
Labels
enhancement New feature or request

Comments

@ioannisj
Copy link
Contributor

Description

This came in from a user:

Oh one last thing I should have mentioned, weirdly the default for file creation on iOS is to make the file encrypted on disk until the device is first unlocked. More and more iOS is prelaunching apps so they load faster, and this often occurs before the device has even unlocked.

Apple isn’t entirely clear on whether prewarming actually runs before the first unlock after a restart. Moreover, Apple's documentation clearly states that prewarming is not intended to execute any application code, even though some online posts have reported that this is not the case (especially on early iOS 15 and scene-based applications)

Regardless, an app could be woken up in the background for other reasons such as:

  • Voip app receiving a voip push notification
  • Geofencing app receiving a region event
  • App may have manually requested a scheduled background task at a specific time

This could indeed interfere with PostHog’s initialisation, even though an edge case

@ioannisj ioannisj added the enhancement New feature or request label Oct 14, 2024
@ioannisj ioannisj self-assigned this Oct 14, 2024
@marandaneto
Copy link
Member

We can inspire from https://github.com/christianselig/TinyStorage which is from the author of this blogpost.

@christianselig
Copy link

Funnily enough I was the one emailing @ioannisj haha after writing that blogpost!

Rather than keeping the conversation isolated to email they mentioned we should probably move the discussion here, which makes sense to me! I basically said this:

  • Weirdly prewarming does run in the applicationDidFinishLaunching window even though the docs say otherwise, which complicates things
  • On of the most perplexing parts of this is that UIApplication.isProtectedDataAvailable is only available in an app’s main target (as UIApplication is only available there), not extensions, so checking it wouldn't work in a widget target, for instance.
  • A second concern, I suppose, would be if in applicationDidFinishLaunching PostHog determines initialization can’t occur due to protected data not being available, and the user sends up an “app did launch” event, would PostHog delay the initialization and the event being sent up until protected data is available, or would the event be lost? @ioannisj mentioned that you'd have to queue them in memory, which means they risk being lost, which they mentioned is not great
  • Per our discussion @ioannisj informed me secondary targets/extensions like widgets still need to have the PostHog setup occur if you want to send up events through there, so an ideal solution would also be compatible in that context

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants