【问题标题】:Xamarin iOS WebView is blankXamarin iOS WebView 为空白
【发布时间】:2020-10-26 11:01:09
【问题描述】:

我正在我的 Xamarin iOS 应用项目中测试 WebView。 WebView 的编码如下:

<WebView
    x:Name="WebView"
    HorizontalOptions="FillAndExpand"
    VerticalOptions="FillAndExpand" 
    android:WebView.EnableZoomControls="true"
    android:WebView.DisplayZoomControls="false"   
>
</WebView>

WebView可以显示html:

 WebView.Source = new HtmlWebViewSource
            {
                Html = "<!DOCTYPE html><html><body><p>Hello world</p></body></html>",
            };

但是当我使用 URL 时:

WebView.Source = new HtmlWebViewSource() { BaseUrl = "https://www.google.com" };

或

WebView.Source = "https://www.google.com";

我只得到一个空白区域。

我已将此添加到 info.plist:

<key>NSAppTransportSecurity</key>
    <dict>
        <key>NSAllowsArbitraryLoadsInWebContent</key>
        <true/>
    </dict>

我不处理任何事件,例如导航、导航等。另外,在这个简单的测试中,我没有覆盖 WebView。

当我打开 Safari 时,iPhone 可以显示 google.com 和其他网站。

可能是什么问题?

【问题讨论】:

  • 您好,确认一下,您设置了水平选项和垂直选项吗?
  • 是的。我现在已将标记添加到问题中。
  • 可以和其他网址一起使用吗?并确保网络权限已打开。

标签: ios xamarin webview xamarin.ios wkwebview


【解决方案1】:

像这样在 viewModel 中添加公共属性:

private string _uri;
    public string Uri
    {
        get { return _uri; }
        set { SetProperty(ref _uri, value); }
    }

然后像这样分配和寻址:

Uri = "http://google.com";

最好在onNavigated to

在你的 xaml 中添加这个

&lt;Grid HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" Padding="5"&gt; &lt;WebView Source="{Binding Uri}"&gt;&lt;/WebView&gt; &lt;/Grid&gt;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-03-07
    • 1970-01-01
    • 2019-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-28
    • 1970-01-01
    相关资源
    最近更新 更多