Dug*_*gan 0 c# android webview ios xamarin
我在过去几天在Xamarin.Forms中开发了一个webview应用程序,并且我已经在Android和iOS模拟器上进行了测试,它似乎在模拟器中运行得很好但是当我去尝试在我自己的Android设备上测试时,它只显示了xamarin splashscreen(我现在使用试用版)然后只是转换到空白的白色屏幕而不是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
}
}
}
Run Code Online (Sandbox Code Playgroud)
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);
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
**更新**我正在使用公司网站,但我一直在测试这个应用程序与许多不同的网站,如谷歌,YouTube和亚马逊.似乎唯一不会在我的设备上显示的网站是我的公司网站(它是一个响应式网站),但所有其他网站都这样做.
从版本9开始,iOS将仅允许您的应用程序与默认情况下实现最佳实践安全性的服务器进行通信.必须在Info.plist中设置值以启用与不安全服务器的通信.
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads </key>
<true/>
</dict>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7800 次 |
| 最近记录: |