From c05bbb3845dfdca90f331ab546c8731e37d789ba Mon Sep 17 00:00:00 2001 From: David Britch Date: Mon, 28 Oct 2024 12:11:21 +0000 Subject: [PATCH] HybridWebView/BlazorWebView updates (#2581) * Default address changed. * InvokeJavaScriptAsync changes return type. --- docs/user-interface/controls/blazorwebview.md | 6 +++--- docs/user-interface/controls/hybridwebview.md | 10 +++++----- docs/whats-new/dotnet-9.md | 6 +++--- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/docs/user-interface/controls/blazorwebview.md b/docs/user-interface/controls/blazorwebview.md index ecafe595f..534460bc2 100644 --- a/docs/user-interface/controls/blazorwebview.md +++ b/docs/user-interface/controls/blazorwebview.md @@ -235,12 +235,12 @@ This switch enables has changed to `localhost`. The internal `0.0.0.0` address used to host content no longer works and results in the not loading any content and rendering as an empty rectangle. +On iOS and Mac Catalyst 18, the default behavior for hosting content in a has changed to `localhost`. The internal `0.0.0.1` address used to host content no longer works and results in the not loading any content and rendering as an empty rectangle. -To opt into using the `0.0.0.0` address, add the following code to the `CreateMauiApp` method in *MauiProgram.cs*: +To opt into using the `0.0.0.1` address, add the following code to the `CreateMauiApp` method in *MauiProgram.cs*: ```csharp -// Set this switch to use the LEGACY behavior of always using 0.0.0.0 to host BlazorWebView +// Set this switch to use the LEGACY behavior of always using 0.0.0.1 to host BlazorWebView AppContext.SetSwitch("BlazorWebView.AppHostAddressAlways0000", true); ``` diff --git a/docs/user-interface/controls/hybridwebview.md b/docs/user-interface/controls/hybridwebview.md index 5aa8ff8b0..e92bb9547 100644 --- a/docs/user-interface/controls/hybridwebview.md +++ b/docs/user-interface/controls/hybridwebview.md @@ -2,7 +2,7 @@ title: HybridWebView description: Learn how to use a HybridWebView to host HTML/JS/CSS content in a WebView, and communicate between that content and .NET. ms.topic: concept-article -ms.date: 09/20/2024 +ms.date: 10/28/2024 monikerRange: ">=net-maui-9.0" #customer intent: As a developer, I want to host HTML/JS/CSS content in a web view so that I can publish the web app as a mobile app. @@ -196,7 +196,7 @@ To create a .NET MAUI app with a : Your app's C# code can synchronously and asynchronously invoke JavaScript methods within the , with optional parameters and an optional return value. This can be achieved with the `InvokeJavaScriptAsync` and `EvaluateJavaScriptAsync` methods: - The `EvaluateJavaScriptAsync` method runs the JavaScript code provided via a parameter and returns the result as a string. -- The `InvokeJavaScriptAsync` method invokes a specified JavaScript method, optionally passing in parameter values, and returns a string containing the return value of the JavaScript method. Internally, parameters and return values are JSON encoded. +- The `InvokeJavaScriptAsync` method invokes a specified JavaScript method, optionally passing in parameter values, and specifies a generic argument that indicates the type of the return value. It returns an object of the generic argument type that contains the return value of the called JavaScript method. Internally, parameters and return values are JSON encoded. ### Invoke synchronous JavaScript @@ -214,7 +214,7 @@ The `AddNumbers` JavaScript method can be invoked from C# with the `InvokeJavaSc double x = 123d; double y = 321d; -var result = await hybridWebView.InvokeJavaScriptAsync( +double result = await hybridWebView.InvokeJavaScriptAsync( "AddNumbers", // JavaScript method name HybridSampleJSContext.Default.Double, // JSON serialization info for return type [x, y], // Parameter values @@ -256,14 +256,14 @@ async function EvaluateMeWithParamsAndAsyncReturn(s1, s2) { The `EvaluateMeWithParamsAndAsyncReturn` JavaScript method can be invoked from C# with the `InvokeJavaScriptAsync` method: ```csharp -var asyncResult = await hybridWebView.InvokeJavaScriptAsync>( +Dictionary asyncResult = await hybridWebView.InvokeJavaScriptAsync>( "EvaluateMeWithParamsAndAsyncReturn", // JavaScript method name HybridSampleJSContext.Default.DictionaryStringString, // JSON serialization info for return type ["new_key", "new_value"], // Parameter values [HybridSampleJSContext.Default.String, HybridSampleJSContext.Default.String]); // JSON serialization info for each parameter ``` -In this example, `asyncResult` is a `Dictionary` containing the JSON data from the web request. +In this example, `asyncResult` is a `Dictionary` that contains the JSON data from the web request. The method invocation requires specifying `JsonTypeInfo` objects that include serialization information for the types used in the operation. These objects are automatically created by including the following `partial` class in your project: diff --git a/docs/whats-new/dotnet-9.md b/docs/whats-new/dotnet-9.md index 85df41407..196e34c04 100644 --- a/docs/whats-new/dotnet-9.md +++ b/docs/whats-new/dotnet-9.md @@ -144,12 +144,12 @@ The binding mode for `IsVisible` and `IsEnabled` on a to `localhost`. The internal `0.0.0.0` address used to host content no longer works and results in the not loading any content and rendering as an empty rectangle. +On iOS and Mac Catalyst 18, .NET MAUI 9 changes the default behavior for hosting content in a to `localhost`. The internal `0.0.0.1` address used to host content no longer works and results in the not loading any content and rendering as an empty rectangle. -To opt into using the `0.0.0.0` address, add the following code to the `CreateMauiApp` method in *MauiProgram.cs*: +To opt into using the `0.0.0.1` address, add the following code to the `CreateMauiApp` method in *MauiProgram.cs*: ```csharp -// Set this switch to use the LEGACY behavior of always using 0.0.0.0 to host BlazorWebView +// Set this switch to use the LEGACY behavior of always using 0.0.0.1 to host BlazorWebView AppContext.SetSwitch("BlazorWebView.AppHostAddressAlways0000", true); ```