Former-commit-id: 068a0d9a11392aa04d68d5c7441402bb35e09625
TangShanKaiPing
wanggang 5 years ago
parent be75b1f58a
commit fac3fe100e

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.companyname.xamarinapp"> <manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.nbaxp.iot" android:installLocation="auto">
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="28" /> <uses-sdk android:minSdkVersion="21" android:targetSdkVersion="28" />
<application android:label="XamarinApp.Android"></application> <application android:label="XamarinApp.Android"></application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
</manifest> </manifest>

@ -2,37 +2,37 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0"> <plist version="1.0">
<dict> <dict>
<key>UIDeviceFamily</key> <key>UIDeviceFamily</key>
<array> <array>
<integer>1</integer> <integer>1</integer>
<integer>2</integer> <integer>2</integer>
</array> </array>
<key>UISupportedInterfaceOrientations</key> <key>UISupportedInterfaceOrientations</key>
<array> <array>
<string>UIInterfaceOrientationPortrait</string> <string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string> <string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string> <string>UIInterfaceOrientationLandscapeRight</string>
</array> </array>
<key>UISupportedInterfaceOrientations~ipad</key> <key>UISupportedInterfaceOrientations~ipad</key>
<array> <array>
<string>UIInterfaceOrientationPortrait</string> <string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string> <string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string> <string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string> <string>UIInterfaceOrientationLandscapeRight</string>
</array> </array>
<key>MinimumOSVersion</key> <key>MinimumOSVersion</key>
<string>8.0</string> <string>8.0</string>
<key>CFBundleDisplayName</key> <key>CFBundleDisplayName</key>
<string>XamarinApp</string> <string>XamarinApp</string>
<key>CFBundleIdentifier</key> <key>CFBundleIdentifier</key>
<string>com.companyname.XamarinApp</string> <string>com.nbaxp.iot</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
<string>1.0</string> <string>1.0</string>
<key>UILaunchStoryboardName</key> <key>UILaunchStoryboardName</key>
<string>LaunchScreen</string> <string>LaunchScreen</string>
<key>CFBundleName</key> <key>CFBundleName</key>
<string>XamarinApp</string> <string>XamarinApp</string>
<key>XSAppIconAssets</key> <key>XSAppIconAssets</key>
<string>Assets.xcassets/AppIcon.appiconset</string> <string>Assets.xcassets/AppIcon.appiconset</string>
</dict> </dict>
</plist> </plist>

@ -0,0 +1,23 @@
using System.Runtime.InteropServices;
using Xamarin.Essentials;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
using XamarinApp.iOS;
[assembly: ExportRenderer(typeof(WebView), typeof(CustomWebViewRenderer))]
namespace XamarinApp.iOS
{
public class CustomWebViewRenderer : WkWebViewRenderer
{
protected override void OnElementChanged(VisualElementChangedEventArgs e)
{
base.OnElementChanged(e);
if (e.NewElement != null)
{
CustomUserAgent = $"{DeviceInfo.Manufacturer}~{DeviceInfo.Model}~{Device.RuntimePlatform}~{(Device.Idiom == TargetIdiom.Tablet ? "ipad" : "iphone")}";
}
}
}
}

@ -62,9 +62,13 @@
<CodesignKey>iPhone Developer</CodesignKey> <CodesignKey>iPhone Developer</CodesignKey>
<CodesignEntitlements>Entitlements.plist</CodesignEntitlements> <CodesignEntitlements>Entitlements.plist</CodesignEntitlements>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(RunConfiguration)' == 'Default' ">
<AppExtensionDebugBundleId />
</PropertyGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Main.cs" /> <Compile Include="Main.cs" />
<Compile Include="AppDelegate.cs" /> <Compile Include="AppDelegate.cs" />
<Compile Include="WkWebViewRenderer.cs" />
<None Include="Entitlements.plist" /> <None Include="Entitlements.plist" />
<None Include="Info.plist" /> <None Include="Info.plist" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />

@ -9,7 +9,12 @@ namespace XamarinApp
public App() public App()
{ {
InitializeComponent(); InitializeComponent();
#if DEBUG
foreach (var res in this.GetType().Assembly.GetManifestResourceNames())
{
System.Diagnostics.Debug.WriteLine($"resource:{res} ");
}
#endif
MainPage = new MainPage(); MainPage = new MainPage();
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

@ -5,8 +5,13 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" mc:Ignorable="d"
x:Class="XamarinApp.MainPage"> x:Class="XamarinApp.MainPage">
<AbsoluteLayout BackgroundColor="LightBlue"> <AbsoluteLayout BackgroundColor="LightBlue" AnchorX="0" AnchorY="0">
<WebView x:Name="webView" AbsoluteLayout.LayoutBounds="0,0,1,1" AbsoluteLayout.LayoutFlags="All" /> <WebView x:Name="webView" AbsoluteLayout.LayoutBounds="0,0,1,1" AbsoluteLayout.LayoutFlags="All" />
<ImageButton Source="options.png" BackgroundColor="Transparent" HorizontalOptions="Center" VerticalOptions="Center" WidthRequest="48" HeightRequest="48" AbsoluteLayout.LayoutBounds="1,1,48,48" AbsoluteLayout.LayoutFlags="PositionProportional" Clicked="ImageButton_Clicked" /> <ImageButton
x:Name="option"
Clicked="ImageButton_Clicked"
BackgroundColor="Transparent"
AbsoluteLayout.LayoutBounds="1,1,48,48"
AbsoluteLayout.LayoutFlags="PositionProportional" />
</AbsoluteLayout> </AbsoluteLayout>
</ContentPage> </ContentPage>

@ -15,6 +15,7 @@ namespace XamarinApp
public MainPage() public MainPage()
{ {
InitializeComponent(); InitializeComponent();
this.option.Source = ImageSource.FromResource($"{this.GetType().Assembly.GetName().Name}.Images.options.png");
this._configFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "config.txt"); this._configFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "config.txt");
if (!File.Exists(this._configFile)) if (!File.Exists(this._configFile))
{ {
@ -43,9 +44,13 @@ namespace XamarinApp
private async Task SetBaseUrl() private async Task SetBaseUrl()
{ {
this._baseUrl = await DisplayPromptAsync("服务器", "配置服务器地址", "确定", "取消", this._baseUrl, keyboard: Keyboard.Url, initialValue: this._baseUrl); var input = await DisplayPromptAsync("服务器", "配置服务器地址", "确定", "取消", this._baseUrl, keyboard: Keyboard.Url, initialValue: this._baseUrl);
File.WriteAllText(this._configFile, this._baseUrl); if (!string.IsNullOrEmpty(input))
this.webView.Source = this._baseUrl; {
this._baseUrl = input;
File.WriteAllText(this._configFile, this._baseUrl);
this.webView.Source = this._baseUrl;
}
} }
} }
} }

@ -10,6 +10,14 @@
<DebugSymbols>true</DebugSymbols> <DebugSymbols>true</DebugSymbols>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<None Remove="Images\options.png" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Images\options.png" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Xamarin.Forms" Version="4.5.0.396" /> <PackageReference Include="Xamarin.Forms" Version="4.5.0.396" />
<PackageReference Include="Xamarin.Essentials" Version="1.5.1" /> <PackageReference Include="Xamarin.Essentials" Version="1.5.1" />

@ -29,6 +29,11 @@ namespace WebMVC
if (env.IsDevelopment()) if (env.IsDevelopment())
{ {
app.UseDeveloperExceptionPage(); app.UseDeveloperExceptionPage();
app.Use(async (context, next) =>
{
System.Console.WriteLine(context.Request.Headers["user-agent"]);
await next.Invoke();
});
} }
else else
{ {
@ -51,11 +56,6 @@ namespace WebMVC
name: "default", name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}"); pattern: "{controller=Home}/{action=Index}/{id?}");
}); });
app.Use(async (context, next) =>
{
await next.Invoke();
});
} }
} }
} }

@ -29,6 +29,11 @@ namespace WebSPA
if (env.IsDevelopment()) if (env.IsDevelopment())
{ {
app.UseDeveloperExceptionPage(); app.UseDeveloperExceptionPage();
app.Use(async (context, next) =>
{
System.Console.WriteLine(context.Request.Headers["user-agent"]);
await next.Invoke();
});
} }
else else
{ {
@ -50,11 +55,6 @@ namespace WebSPA
name: "default", name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}"); pattern: "{controller=Home}/{action=Index}/{id?}");
}); });
app.Use(async (context, next) =>
{
await next.Invoke();
});
} }
} }
} }

@ -33,11 +33,11 @@ http {
location / { location / {
#proxy_set_header Host $host:$server_port; #proxy_set_header Host $host:$server_port;
proxy_pass http://localhost:5001/;
if ($http_user_agent ~* "(mobile|android|ipad|iphone|ipod|tablet)") { if ($http_user_agent ~* "(mobile|android|ipad|iphone|ipod|tablet)") {
#rewrite ^(.*) http://localhost:5002$1 permanent;
proxy_pass http://localhost:5002; proxy_pass http://localhost:5002;
break;
} }
proxy_pass http://localhost:5001/;
} }
location ^~ /dfs/ { location ^~ /dfs/ {

Loading…
Cancel
Save