gpt4 book ai didi

c# - Xamarin Forms webview 未在设备上显示

转载 作者:行者123 更新时间:2023-11-28 18:05:05 25 4
gpt4 key购买 nike

过去几天我在 Xamarin.Forms 中开发了一个 webview 应用程序,我一直在 android 和 iOS 模拟器上测试它,它似乎在模拟器中工作得很好但是当我去尝试自己测试它时Android 设备,它只显示了 xamarin 启动画面(我目前使用的是试用版),然后只是过渡到空白屏幕而不是 webview。

有没有人知道为什么要这样做?

我将在下面附上我的代码:App.cs

using Xamarin.Forms;

namespace WebViewApp
{
public class App() : Application
{
public App()
{
// The root page of your application
MainPage = new WebPage();
}

protected override void OnStart()
{
// Handle when your app starts
}

protected override void OnSleep()
{
// Handle when your app sleeps
}

protected override void OnResume()
{
// Handle when your app resumes
}
}
}

WebPage.cs

using Xamarin.Forms;

namespace WebViewApp
{
public class WebPage : ContentPage
{
private const string URL = "https://www.google.com";
private const int PADDING_WIDTH = 0;

private int paddingHeight;

private WebView webView;

public WebPage()
{
webView = new WebView
{
Source = URL,
VerticalOptions = LayoutOptions.FillAndExpand,
HorizontalOptions = LayoutOptions.FillAndExpand
};

CheckDevice();

Content = new StackLayout
{
Padding = new Thickness(PADDING_WIDTH, GetPaddingHeight()),
Chrildren = { webView }
};
}

public int GetPaddingHeight()
{
return paddingHeight;
}

/// <summary>
/// This will set the padding height for the webview when displayed
/// <summary>
/// <param name="pHeight">Set integer value for the padding height.</param>
public void SetPaddingHeight(int pHeight)
{
paddingHeight = pHeight;
}

private void CheckDevice()
{
if(Device.OS == TargetPlatform.Android)
{
SetPaddingHeight(0);
}
else if(Device.OS == TargetPlatform.iOS)
{
SetPaddingHeight(20);
}
}
}
}

**更新**我正在使用公司网站,但我一直在使用许多不同的网站(如谷歌、YouTube 和亚马逊)测试此应用程序。似乎唯一不会在我的设备上显示的网站是我公司的网站(它是一个响应式网站),但所有其他网站都会显示。

最佳答案

自版本 9 起,iOS 将只允许您的应用程序与默认实现最佳安全实践的服务器通信。必须在 Info.plist 中设置值以启用与不安全服务器的通信。

<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads </key>
<true/>
</dict>

关于c# - Xamarin Forms webview 未在设备上显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34414423/

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