Skip to content

Commit 77fb12f

Browse files
authored
Ensure WKWebView is initialized in main thread (#70)
Fixes #69.
1 parent ffb6d0b commit 77fb12f

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

Sources/Segment/Plugins/Platforms/Vendors/AppleUtils.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,11 @@ internal class iOSVendorSystem: VendorSystem {
6565

6666
override var userAgent: String? {
6767
#if !os(tvOS)
68-
return WKWebView().value(forKey: "userAgent") as? String
68+
var userAgent: String?
69+
DispatchQueue.main.sync {
70+
userAgent = WKWebView().value(forKey: "userAgent") as? String
71+
}
72+
return userAgent
6973
#else
7074
// webkit isn't on tvos
7175
return "unknown"
@@ -228,7 +232,11 @@ internal class MacOSVendorSystem: VendorSystem {
228232
}
229233

230234
override var userAgent: String? {
231-
return WKWebView().value(forKey: "userAgent") as? String
235+
var userAgent: String?
236+
DispatchQueue.main.sync {
237+
userAgent = WKWebView().value(forKey: "userAgent") as? String
238+
}
239+
return userAgent
232240
}
233241

234242
override var connection: ConnectionStatus {

0 commit comments

Comments
 (0)