gpt4 book ai didi

ios - Xamarin.Forms WebView、WKWebViewConfiguration 和发送 "Mobile" header

转载 作者:行者123 更新时间:2023-12-01 16:19:59 24 4
gpt4 key购买 nike

我正在重新使用 Xamarin.Forms,并且我发现了 iPad 上 iOS 13 Safari 的一种新行为,称为“桌面级浏览”。它在这里详细介绍:
https://developer.apple.com/videos/play/wwdc2019/203
我的问题是我需要我的 Web 应用程序能够检测普通 Web 浏览器是否正在查看它,或者它是否正被 Xamarin.Forms.WebView 查看。 .在我的 Web 应用程序中,我曾经能够使用用户代理字符串或 X-Requested-With 检测 Web View 。标题。但是,如果我的 Web View 在 iOS 13 上的 iPad 上运行,它将进入桌面模式,这会产生桌面 Safari 用户代理一个 no X-Requested-With header ,我无法再检测到它是 Web View 。上述视频中的 2:56 引用了这一点。
在原生 iOS 应用程序中,我显然可以使用 WKWebViewConfiguration控制这些类似桌面的功能:
https://developer.apple.com/documentation/webkit/wkwebviewconfiguration
我认为这是在我的第一个链接的视频中的 9:01 演示的。
如何使用 WKWebViewConfiguration与 Xamarin.Forms?我看到一个 WebKit.WKWebViewConfiguration类,但我怎样才能将它与 Xamarin.Forms.WebView 一起使用?

最佳答案

除非您按照 this article 中的步骤进行操作,您的应用正在使用 UIWebView 而不是 WKWebView
有几种方法可以编辑 WKWebViewConfiguration :

  • 您可以使用“Custom Renderer”来实现您自己的 WKWebView,如 Official Xamarin Forms example 所示。 ,并在那里编辑 WKWebViewConfiguration。
  • 我还没有尝试过的另一种可能的方法-您还可以使用步骤 mentioned here 在表单中实现 WKWebView .然后只需编辑该属性。
  • 关于ios - Xamarin.Forms WebView、WKWebViewConfiguration 和发送 "Mobile" header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62960504/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com