Repository navigation
fix(ios): align user agent with analytics-swift - #222
Merged
Merged
Conversation
getContext read the user agent by creating a WKWebView. The first web view in a process has to start WebKit, which blocks the main thread at launch (~290ms on an iPhone 12). Since Flutter 3.29 runs Dart on the platform thread, that also stalls Flutter frames. Build the string from the device model and OS version instead, as analytics-swift does since segmentio/analytics-swift#341, compute it once, and drop the WebKit import on iOS and macOS.
MichaelGHSeg
approved these changes
Oct 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #221
What
This aligns the plugin's iOS and macOS user agent with analytics-swift's
UserAgent.swift, which replaced the sameWKWebViewlookup in analytics-swift#341 (released in 1.5.12).UIDevice.current.modelandProcessInfo.operatingSystemVersion, using the same format as analytics-swift. It's computed once in astatic let, so it's safe to read from any thread.import WebKitand theDispatchQueue.main.syncfallback are removed.AppleUtils.swiftgets the same change in both theios/andmacos/source trees.Why
The first
WKWebViewin a process starts WebKit. In a profile build of our app on an iPhone 12 (iOS 26.3), this blocked the main thread for about 290ms at launch. Generating the string instead broughtgetContextdown to ~0.5ms. Since Flutter 3.29 (iOS) and 3.35 (macOS), Dart runs on the main thread, so the block stalls Flutter frames directly. analytics-swift made this change after the same call caused hangs and crashes (#229, #353).Behaviour change
The output now matches analytics-swift byte for byte. Compared with the WebKit value the plugin sent before:
iPhone; CPU iPhone OS 18_7iPhone; CPU iPhone OS 26_5iPad; CPU OS 18_7iPad; CPU iPad OS 26_5Testing
UserAgentTests.swiftagainst thisAppleUtils.swift. It checks the format, caching across threads, and comparison withWKWebView. It passes on iPhone 17 Pro and iPad Pro 11" (iOS 26.5), iPhone 14 (iOS 16.0), and macOS 26.5. It isn't included because the repo has no native test target.