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

Add UserAgentDefaults for Managing User Agent String Persistence #992

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

weibel
Copy link
Contributor

@weibel weibel commented May 31, 2024

Motivation

The creation of a WKWebView and subsequent execution of javascript to get a proper user agent string on app startup counts negatively against the app startup time. Depending on iOS version and device it can be in the hundreds of milliseconds. Since the user agent string only changes on iOS updates it's a good candidate for persistence between app starts

Summary

This pull request introduces the UserAgentDefaults class to manage the persistence of user agent strings within the application. The UserAgentService has been updated to utilize this new class, ensuring that user agents are efficiently stored and retrieved from UserDefaults.

Key Changes

UserAgentDefaults Class

  • Implements UserAgentPersistence protocol to handle user agent persistence.
  • Uses UserDefaults for storing user agent strings, keyed by the current OS version.
  • Includes a contents property to fetch the entire user agent dictionary from UserDefaults.
  • Provides methods for setting, getting, and resetting the user agent.

UserAgentService Updates

  • Utilizes UserAgentDefaults for managing user agent persistence.

- Implement UserAgentDefaults class to handle user agent persistence using UserDefaults.
- Ensure user agent is keyed by the current OS version.
- Update UserAgentService to use UserAgentDefaults for persistence.
@weibel
Copy link
Contributor Author

weibel commented Jun 4, 2024

@YuriyVelichkoPI
In this comment, I mentioned persisting the user agent string keyed by the OS version. This PR is my take on an implementation. It will save the time of initializing a WKWebView and running the JavaScript on most app starts.

Copy link
Contributor

@YuriyVelichkoPI YuriyVelichkoPI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

It's a good way to improve first ad call performance.

@OlenaPostindustria, can you take a look to and ensure that everything works fine and all needed tests are present.

@OlenaPostindustria
Copy link
Collaborator

@YuriyVelichkoPI

Looks good to me!

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

Successfully merging this pull request may close these issues.

3 participants