Skip to content

Commit

Permalink
Update network settings for Android and iOS
Browse files Browse the repository at this point in the history
- MainPage.xaml: Added XML namespace `local` for `eShop.HybridApp.Components`.
- MauiProgram.cs: Updated `MobileBffHost` URL for Android to `http://10.0.2.2:11632/` and kept `http://localhost:11632/` for other platforms.
- AndroidManifest.xml: Enabled cleartext traffic and added network security config.
- Info.plist: Relaxed network security policies to allow HTTP connections.
- network_security_config.xml: Created to permit cleartext traffic for `10.0.2.2`.
  • Loading branch information
jamesmontemagno committed Oct 19, 2024
1 parent 154820a commit 48a9da8
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/HybridApp/MainPage.xaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:eShop.HybridApp"
xmlns:local="clr-namespace:eShop.HybridApp.Components"
x:Class="eShop.HybridApp.MainPage"
BackgroundColor="{DynamicResource PageBackgroundColor}">

Expand Down
2 changes: 1 addition & 1 deletion src/HybridApp/MauiProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace eShop.HybridApp;
public static class MauiProgram
{
// NOTE: Must have a trailing slash on base URLs to ensure the full BaseAddress URL is used to resolve relative URLs
internal static string MobileBffHost = "http://localhost:11632/";
internal static string MobileBffHost = DeviceInfo.Platform == DevicePlatform.Android ? "http://10.0.2.2:11632/" : "http://localhost:11632/";


public static MauiApp CreateMauiApp()
Expand Down
4 changes: 3 additions & 1 deletion src/HybridApp/Platforms/Android/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application android:allowBackup="true" android:icon="@mipmap/appicon" android:roundIcon="@mipmap/appicon_round" android:supportsRtl="true"></application>
<application android:allowBackup="true" android:icon="@mipmap/appicon" android:roundIcon="@mipmap/appicon_round" android:supportsRtl="true" android:usesCleartextTraffic="true" android:networkSecurityConfig="@xml/network_security_config">

</application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">10.0.2.2</domain>
</domain-config>
</network-security-config>
5 changes: 5 additions & 0 deletions src/HybridApp/Platforms/MacCatalyst/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>XSAppIconAssets</key>
<string>Assets.xcassets/appicon.appiconset</string>
</dict>
Expand Down
5 changes: 5 additions & 0 deletions src/HybridApp/Platforms/iOS/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,10 @@
</array>
<key>XSAppIconAssets</key>
<string>Assets.xcassets/appicon.appiconset</string>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsLocalNetworking</key>
<true/>
</dict>
</dict>
</plist>

0 comments on commit 48a9da8

Please sign in to comment.