mirror of
https://github.com/yattee/yattee.git
synced 2024-12-22 21:43:41 +00:00
tvOS does not support WebKit
This commit is contained in:
parent
2e9cceafa5
commit
7c9810ddf0
@ -1,28 +1,37 @@
|
|||||||
import Logging
|
import Logging
|
||||||
|
#if !os(tvOS)
|
||||||
import WebKit
|
import WebKit
|
||||||
|
#endif
|
||||||
|
|
||||||
final class UserAgentManager {
|
final class UserAgentManager {
|
||||||
static let shared = UserAgentManager()
|
static let shared = UserAgentManager()
|
||||||
|
|
||||||
private(set) var userAgent: String
|
private(set) var userAgent: String
|
||||||
|
#if !os(tvOS)
|
||||||
private var webView: WKWebView?
|
private var webView: WKWebView?
|
||||||
|
#endif
|
||||||
|
|
||||||
private init() {
|
private init() {
|
||||||
// In case an error occurs while retrieving the actual User-Agent,
|
/*
|
||||||
// we set a default User-Agent value that represents a commonly used User-Agent.
|
In case an error occurs while retrieving the actual User-Agent, and on tvOS,
|
||||||
userAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)"
|
we set a default User-Agent value that represents a commonly used User-Agent.
|
||||||
|
*/
|
||||||
|
|
||||||
|
userAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)"
|
||||||
|
#if !os(tvOS)
|
||||||
webView = WKWebView()
|
webView = WKWebView()
|
||||||
webView?.evaluateJavaScript("navigator.userAgent") { [weak self] result, _ in
|
webView?.evaluateJavaScript("navigator.userAgent") { [weak self] result, _ in
|
||||||
if let userAgent = result as? String {
|
if let userAgent = result as? String {
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
self?.userAgent = userAgent
|
self?.userAgent = userAgent
|
||||||
Logger(label: "stream.yattee.userAgentManager").info("User-Agent: \(userAgent)")
|
Logger(label: "stream.yattee.userAgentManager").info("User-Agent: \(userAgent)")
|
||||||
print("User-Agent updated: \(userAgent)")
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Logger(label: "stream.yattee.userAgentManager").warning("Failed to update User-Agent.")
|
Logger(label: "stream.yattee.userAgentManager").warning("Failed to update User-Agent.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
Logger(label: "stream.yattee.userAgentManager.tvOS").info("User-Agent: \(userAgent)")
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user