【问题标题】:iOS WKWebview UserAgent is being set on iPhone but not for iPadiOS WKWebview UserAgent 正在 iPhone 上设置,但不适用于 iPad
【发布时间】:2021-02-23 14:46:02
【问题描述】:

当我在 iPhone 上的 wkwebview 中打开或启动该网站时,它会自动在请求标头中获取应用程序“userAgent”,但在相同的情况下它不会发生在 iPad 上。

在下面创建 WKWebview:

让 wkWebView = WKWebView()

【问题讨论】:

    标签: ios swift iphone xcode ipad


    【解决方案1】:

    您可以创建WKWebViewConfiguration 并将其与WKWebView 创建一起传递。

    // Create custom configuration object.
    let webConfiguration = WKWebViewConfiguration()
    webConfiguration.applicationNameForUserAgent = "Add your user agent here."
    
    // Create WebView object with your configuration object.
    let webView = WKWebView(frame: view.frame, configuration: webConfiguration)
    

    这样它将适用于您的所有设备。

    【讨论】:

    • 知道为什么它适用于 iPhone 的 let wkWebView = WKWebView() 但不适用于 iPad?
    • 不看代码我无法给你音乐会答案。
    猜你喜欢
    • 2011-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-16
    • 1970-01-01
    相关资源
    最近更新 更多